From a7a26779d6e5b1d82c96de3ce2d0ec0103c33891 Mon Sep 17 00:00:00 2001 From: Ross Ceballo Date: Tue, 19 Nov 2024 15:24:42 -0500 Subject: [PATCH] Add test file for gha --- .github/workflows/build.yaml | 1 - .github/workflows/test.yaml | 266 +++++++++++++++++++++++++++++++++++ setup.cfg | 2 +- setup.py | 79 +++++------ 4 files changed, 306 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7a3af42..c3c8bd8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,7 +17,6 @@ jobs: id: build with: github_token: ${{ secrets.GITHUB_TOKEN }} - docker_token: ${{ secrets.DOCKER_TOKEN }} dockerfile: docker/Dockerfile platforms: linux/amd64,linux/arm64 image: ${{ github.repository }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..e655610 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,266 @@ +name: Test + +on: + push: + branches: + - main + tags: + pull_request: + +jobs: + tests: + strategy: + matrix: + include: + - test: pytest + - test: github-tag-release + - test: github-tag-teams + - test: github-decimate-org + - test: github-fork-org + - test: github-get-ratelimit + - test: github-auth + - test: github-list-repos + - test: github-mv-repos-to-team + - test: github-auth-debug + env: + DM_SQUARE_DEBUG: 'bogus_non_int_able_value' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - name: Install deps + run: | + pip install --upgrade pip setuptools_scm 'setuptools==58' + #if [ "${{ matrix.test }}" == "github-tag-release" ]; then + python setup.py sdist + pip install dist/sqre-codekit-*.tar.gz + #fi + - name: Run Tests + env: + SQREADMIN_TOKEN: ${{ secrets.SQREADMIN_TOKEN }} + DM_SQUARE_DEBUG: ${{ matrix.env.DM_SQUARE_DEBUG || '' }} + run: | + set -e + TEST=${{ matrix.test }} + case "$TEST" in + pytest) + python setup.py test + ;; + + github-tag-release) + set -e + # check argparse help formatting for errors + "$TEST" -h + + if [ -n "$SQREADMIN_TOKEN" ]; then + # verify a past weekly tag -- the eups tag name and git tag names are + # in sync except for s/_/-/ + "$TEST" \ + --verify \ + --debug \ + --limit 10 \ + --org 'lsst' \ + --allow-team 'Data Management' \ + --allow-team 'DM Externals' \ + --external-team 'DM Externals' \ + --deny-team 'DM Auxilliaries' \ + --email 'sqre-admin@lists.lsst.org' \ + --user 'sqreadmin' \ + --token "$SQREADMIN_TOKEN" \ + --ignore-git-tagger \ + --ignore-git-message \ + --manifest 'b3595' \ + 'w.2018.18' + + # verify a past official release where the git tag was generated from + # an rcX eups tag. This validates the location of the git tags but + # does not inspect the official eups release tag at all. + "$TEST" \ + --verify \ + --debug \ + --limit 10 \ + --org 'lsst' \ + --allow-team 'Data Management' \ + --allow-team 'DM Externals' \ + --external-team 'DM Externals' \ + --deny-team 'DM Auxilliaries' \ + --email 'sqre-admin@lists.lsst.org' \ + --user 'sqreadmin' \ + --token "$SQREADMIN_TOKEN" \ + --ignore-git-tagger \ + --ignore-git-message \ + --eups-tag 'v15_0_rc3' \ + --manifest 'b3504' \ + '15.0' + + # verify a past official release using the eups tag. As the eups + # product version strings will be out of sync between the versiondb + # manifest it was based on and the eups tag, the eups product version + # strings have to be ignored. + "$TEST" \ + --verify \ + --debug \ + --limit 10 \ + --org 'lsst' \ + --allow-team 'Data Management' \ + --allow-team 'DM Externals' \ + --external-team 'DM Externals' \ + --deny-team 'DM Auxilliaries' \ + --email 'sqre-admin@lists.lsst.org' \ + --user 'sqreadmin' \ + --token "$SQREADMIN_TOKEN" \ + --ignore-manifest-versions \ + --ignore-git-tagger \ + --ignore-git-message \ + --manifest 'b3504' \ + '15.0' + + "$TEST" \ + --dry-run \ + --debug \ + --limit 10 \ + --org 'lsst' \ + --allow-team 'Data Management' \ + --allow-team 'DM Externals' \ + --external-team 'DM Externals' \ + --deny-team 'DM Auxilliaries' \ + --email 'sqre-admin@lists.lsst.org' \ + --user 'sqreadmin' \ + --token "$SQREADMIN_TOKEN" \ + --ignore-manifest-versions \ + --ignore-git-tagger \ + --ignore-git-message \ + --manifest 'b3595' \ + --manifest-only \ + 'w.2018.18' + else + echo "Unable to test without secure env vars." + fi + ;; + + github-tag-teams) + "$TEST" -h + if [ -n "$SQREADMIN_TOKEN" ]; then + # check argparse help formatting for errors + # create + "$TEST" \ + --debug \ + --dry-run \ + --org 'lsst' \ + --allow-team 'DM Auxilliaries' \ + --deny-team 'DM Externals' \ + --token "$SQREADMIN_TOKEN" \ + --user 'sqreadmin' \ + --email 'sqre-admin@lists.lsst.org' \ + --tag 'foo' \ + --tag 'bar' + + # --delete + "$TEST" \ + --debug \ + --dry-run \ + --delete \ + --org 'lsst' \ + --allow-team 'DM Auxilliaries' \ + --deny-team 'DM Externals' \ + --token "$SQREADMIN_TOKEN" \ + --user 'sqreadmin' \ + --email 'sqre-admin@lists.lsst.org' \ + --tag 'foo' \ + --tag 'bar' + else + echo "Unable to test without travis secure env vars." + fi + ;; + + github-decimate-org) + "$TEST" -h + if [ -n "$SQREADMIN_TOKEN" ]; then + "$TEST" \ + --dry-run \ + --debug \ + --org 'batmanuel-sandbox' \ + --token "$SQREADMIN_TOKEN" \ + --delete-repos \ + --delete-repos-limit 3 \ + --delete-teams \ + --delete-teams-limit 3 + else + echo "Unable to test without travis secure env vars." + fi + ;; + + github-fork-org) + # check argparse help formatting for errors + "$TEST" -h + if [ -n "$SQREADMIN_TOKEN" ]; then + "$TEST" \ + --dry-run \ + --debug \ + --src-org 'lsst' \ + --dst-org 'batmanuel-sandbox' \ + --token "$SQREADMIN_TOKEN" \ + --team 'DM Auxilliaries' \ + --team 'DM Externals' \ + --team 'Data Management' \ + --limit 10 + #--copy-teams + else + echo "Unable to test without travis secure env vars." + fi + ;; + + github-get-ratelimit) + # check argparse help formatting for errors + "$TEST" -h + + if [ -n "$SQREADMIN_TOKEN" ]; then + "$TEST" \ + --debug \ + --token "$SQREADMIN_TOKEN" + else + echo "le to test without travis secure env vars." + fi + ;; + + github-auth-debug) + TEST=github-auth + # should fail + "$TEST" -u foo || true + #[[ $? == 1 ]] + ;; + *) + "$TEST" -h + ;; + + esac + publish: + needs: tests + name: Upload release to PyPI + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-20.04 + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + environment: + name: pypi + url: https://pypi.org/p/ + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.6' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install setuptools wheel twine + - name: Build + run: | + python setup.py sdist bdist_wheel + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + diff --git a/setup.cfg b/setup.cfg index 59175b7..cb9394e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ test=pytest [tool:pytest] -addopts = --flake8 +#addopts = --flake8 [flake8] ignore=E722,W504 diff --git a/setup.py b/setup.py index 25aa625..5418abe 100644 --- a/setup.py +++ b/setup.py @@ -1,26 +1,25 @@ #!/usr/bin/env python3 """Setup Tools Script""" -import os import codecs -from setuptools import setup, find_packages +import os + +from setuptools import find_packages, setup -PACKAGENAME = 'sqre-codekit' -DESCRIPTION = 'LSST Data Management SQuaRE code management tools' -AUTHOR = 'Frossie Economou' -AUTHOR_EMAIL = 'frossie@lsst.org' -URL = 'https://github.com/lsst-sqre/sqre-codekit' -LICENSE = 'MIT' +PACKAGENAME = "sqre-codekit" +DESCRIPTION = "LSST Data Management SQuaRE code management tools" +AUTHOR = "Frossie Economou" +AUTHOR_EMAIL = "frossie@lsst.org" +URL = "https://github.com/lsst-sqre/sqre-codekit" +LICENSE = "MIT" def read(filename): """Convenience function for includes""" - full_filename = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - filename) - return codecs.open(full_filename, 'r', 'utf-8').read() + full_filename = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) + return codecs.open(full_filename, "r", "utf-8").read() -long_description = read('README.md') # pylint:disable=invalid-name +long_description = read("README.md") # pylint:disable=invalid-name setup( name=PACKAGENAME, @@ -32,42 +31,42 @@ def read(filename): author_email=AUTHOR_EMAIL, license=LICENSE, classifiers=[ - 'Development Status :: 4 - Beta', - 'Programming Language :: Python :: 3.6', - 'License :: OSI Approved :: MIT License', + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3.6", + "License :: OSI Approved :: MIT License", ], - keywords='lsst', + keywords="lsst", use_scm_version=True, - packages=find_packages(exclude=['docs', 'tests*']), + packages=find_packages(exclude=["docs", "tests*"]), install_requires=[ - 'MapGitConfig==1.1', - 'progressbar2==3.37.1', - 'public==1.0', - 'pygithub==1.40a3', - 'pyyaml>=5.1', - 'requests>=2.8.1,<3.0.0', + "MapGitConfig==1.1", + "progressbar2==3.37.1", + "public==1.0", + "pygithub==1.59", + "pyyaml>=5.1", + "requests>=2.8.1,<3.0.0", ], setup_requires=[ - 'pytest-runner>=4.4,<5', - 'setuptools_scm', + "pytest-runner>=4.4,<5", + "setuptools_scm", ], tests_require=[ - 'flake8>=3.7.7,<3.8', - 'pytest>=4.3,<5', - 'pytest-flake8>=1.0.4,<2', - 'responses>=0.9.0,<1', + "flake8", + "pytest<5", + # "pytest-flake8", + "responses>=0.9.0,<1", ], # package_data={}, entry_points={ - 'console_scripts': [ - 'github-auth = codekit.cli.github_auth:main', - 'github-decimate-org = codekit.cli.github_decimate_org:main', - 'github-fork-org = codekit.cli.github_fork_org:main', - 'github-get-ratelimit= codekit.cli.github_get_ratelimit:main', - 'github-list-repos = codekit.cli.github_list_repos:main', - 'github-mv-repos-to-team = codekit.cli.github_mv_repos_to_team:main', # NOQA - 'github-tag-release = codekit.cli.github_tag_release:main', - 'github-tag-teams = codekit.cli.github_tag_teams:main', + "console_scripts": [ + "github-auth = codekit.cli.github_auth:main", + "github-decimate-org = codekit.cli.github_decimate_org:main", + "github-fork-org = codekit.cli.github_fork_org:main", + "github-get-ratelimit= codekit.cli.github_get_ratelimit:main", + "github-list-repos = codekit.cli.github_list_repos:main", + "github-mv-repos-to-team = codekit.cli.github_mv_repos_to_team:main", # NOQA + "github-tag-release = codekit.cli.github_tag_release:main", + "github-tag-teams = codekit.cli.github_tag_teams:main", ] - } + }, )