From 48f38e2c84c3e198cc4bbbc4aadf74bed3a22458 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Wed, 6 Nov 2024 05:38:14 -0600 Subject: [PATCH 1/2] Rename the test workflow to better reflect its purpose --- .github/workflows/{build.yaml => test.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build.yaml => test.yaml} (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/test.yaml similarity index 100% rename from .github/workflows/build.yaml rename to .github/workflows/test.yaml From 8ab09968fe49cdb70e9fb8942db133faf7ddbcee Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Wed, 6 Nov 2024 06:07:26 -0600 Subject: [PATCH 2/2] Migrate to a reusable workflow --- .github/workflows/test.yaml | 142 ++++++++++++------------- .pre-commit-config.yaml | 4 + pyproject.toml | 2 +- scripts/ensure_min_python_is_tested.py | 26 ++--- tox.ini | 20 ++-- 5 files changed, 94 insertions(+), 100 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 009ad33bf..eb84c4bb6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,90 +1,80 @@ -name: build +name: "🧪 Test" + on: push: - pull_request: + branches: + - "main" + pull_request: null # build weekly at 4:00 AM UTC schedule: - cron: '0 4 * * 1' jobs: - pylint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: '3.x' - - run: python -m pip install -U tox - - run: tox -e pylint - - mypy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: '3.11' - - run: python -m pip install -U tox - - run: tox -e mypy,mypy-test - test: + name: "${{ matrix.name }}" strategy: + fail-fast: false matrix: - os: [ubuntu-latest] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] - # we do not want a large number of windows and macos builds, so - # enumerate them explicitly + # The `include` array below will match against these names + # and add additional keys and values to the JSON object. + name: + - "Linux" + - "macOS" + - "Windows" + - "Quality" + + # The `include` array below will also inherit these values, + # which are critical for effective cache-busting. + # The nested list syntax ensures that the full array of values is inherited. + cache-key-hash-files: + - + - "requirements/*/*.txt" + - "pyproject.toml" + - "toxfile.py" + include: - - os: windows-latest - python-version: "3.11" - - os: macos-latest - python-version: "3.11" - name: "test py${{ matrix.python-version }} on ${{ matrix.os }} " - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - - name: install tox - run: python -m pip install -U tox - - name: run tests - run: python -m tox -e py,coverage_report + - name: "Linux" + runner: "ubuntu-latest" + cpythons: + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + tox-post-environments: + - "py3.8-mindeps" + - "coverage_report" + + - name: "macOS" + runner: "macos-latest" + cpythons: + - "3.11" + tox-post-environments: + - "coverage_report" - test-lazy-imports: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: '3.x' - - run: python -m pip install -U tox - - run: tox -e test-lazy-imports + - name: "Windows" + runner: "windows-latest" + cpythons: + - "3.11" + tox-post-environments: + - "coverage_report" - test-mindeps: - runs-on: ubuntu-latest - name: "mindeps" - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: "3.8" - - name: install tox - run: python -m pip install -U tox - - name: test - run: tox -e py-mindeps + - name: "Quality" + runner: "ubuntu-latest" + cpythons: + - "3.13" + tox-environments: + - "check-min-python-is-tested" + - "mypy" + - "mypy-test" + - "poetry-check" + - "pylint" + - "test-lazy-imports" + - "twine-check" + cache-paths: + - ".mypy_cache/" - test-package-metadata: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version: "3.11" - - name: install tox - run: python -m pip install -U tox - - name: check package metadata - run: python -m tox -e twine-check,poetry-check - - name: check min version is tested in CI - run: python -m tox r -e check-min-python-is-tested + uses: "globus/workflows/.github/workflows/tox.yaml@04b4abd6fcb9b4be7263bc9d6994ae2ada220739" # v1.1 + with: + config: "${{ toJSON(matrix) }}" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 901174d67..7a1945d4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,6 +54,10 @@ repos: rev: 0.6.7 hooks: - id: alphabetize-codeowners +- repo: https://github.com/rhysd/actionlint + rev: v1.7.4 + hooks: + - id: actionlint # custom local hooks - repo: local diff --git a/pyproject.toml b/pyproject.toml index b2bbe0e12..be74dea09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ attr = "globus_sdk.__version__" # non-packaging tool configs follow [tool.pytest.ini_options] -addopts = "--no-success-flaky-report" +addopts = "--no-success-flaky-report --color=yes" testpaths = ["tests"] norecursedirs = ["tests/non-pytest"] filterwarnings = [ diff --git a/scripts/ensure_min_python_is_tested.py b/scripts/ensure_min_python_is_tested.py index f93521f05..29c29008c 100644 --- a/scripts/ensure_min_python_is_tested.py +++ b/scripts/ensure_min_python_is_tested.py @@ -19,23 +19,23 @@ ) requires_python_version = proc.stdout.decode().strip() -with open(REPO_ROOT / ".github" / "workflows" / "build.yaml") as f: +with open(REPO_ROOT / ".github" / "workflows" / "test.yaml") as f: workflow = YAML.load(f) - try: - test_mindeps_job = workflow["jobs"]["test-mindeps"] - except KeyError: - raise ValueError("Could not find the test-mindeps job. Perhaps it has moved?") - - job_steps = test_mindeps_job["steps"] - for step in job_steps: - if "uses" in step and "actions/setup-python" in step["uses"]: - setup_python_step = step + includes = workflow["jobs"]["test"]["strategy"]["matrix"]["include"] + for include in includes: + if include["name"] == "Linux": break else: - raise ValueError("Could not find the setup-python step.") + raise ValueError("Could not find 'Linux' in the test matrix.") - python_version = setup_python_step["with"]["python-version"] - if python_version != requires_python_version: + for environment in include["tox-post-environments"]: + if environment.endswith("-mindeps"): + break + else: + raise ValueError("Could not find a '-mindeps' tox-post-environment.") + + python_version, _, _ = environment.partition("-") + if python_version != f"py{requires_python_version}": print("ERROR: ensure_min_python_is_tested.py failed!") print( f"\nPackage data sets 'Requires-Python: >={requires_python_version}', " diff --git a/tox.ini b/tox.ini index b50598dde..29be40c94 100644 --- a/tox.ini +++ b/tox.ini @@ -5,13 +5,13 @@ envlist = pylint test-lazy-imports coverage_clean - py{313,312,311,310,39,38} - py38-mindeps + py{3.13,3.12,3.11,3.10,3.9,3.8} + py3.8-mindeps coverage_report docs minversion = 4.22.0 labels = - freezedeps = freezedeps-print,freezedeps-py{313,312,311,310,39,38} + freezedeps = freezedeps-print,freezedeps-py{3.13,3.12,3.11,3.10,3.9,3.8} [testenv] # build a wheel, not a tarball, and use a common env to do it (so that the wheel is shared) @@ -23,8 +23,8 @@ deps = mindeps: -r requirements/py{py_dot_ver}/test-mindeps.txt commands = coverage run -m pytest {posargs} depends = - py{313,312,311,310,39,38}{-mindeps,}: coverage_clean, lint - coverage_report: py{313,312,311,310,39,38}{-mindeps,} + py{3.13,3.12,3.11,3.10,3.9,3.8}{-mindeps,}: coverage_clean, lint + coverage_report: py{3.13,3.12,3.11,3.10,3.9,3.8}{-mindeps,} [testenv:coverage_clean] dependency_groups = coverage @@ -65,7 +65,7 @@ deps = pyright commands = pyright src/ {posargs} [testenv:docs] -# force use of py311 for doc builds so that we get the same behaviors as the +# force use of py3.11 for doc builds so that we get the same behaviors as the # readthedocs doc build basepython = python3.11 deps = -r requirements/py{py_dot_ver}/docs.txt @@ -104,7 +104,7 @@ commands = python -m dependency_groups typing -o requirements/.typing.in python -m dependency_groups test-mindeps -o requirements/.test-mindeps.in python -m dependency_groups docs -o requirements/.docs.in -[testenv:freezedeps-py{313,312,311,310,39,38}] +[testenv:freezedeps-py{3.13,3.12,3.11,3.10,3.9,3.8}] description = freeze development dependencies using pip-compile skip_install = true setenv = @@ -116,10 +116,10 @@ commands = pip-compile --strip-extras -q -U --resolver=backtracking .typing.in -o py{py_dot_ver}/typing.txt # Minimum dependencies are only tested against the lowest supported Python version. - py38: pip-compile --strip-extras -q -U --resolver=backtracking .test-mindeps.in -o py{py_dot_ver}/test-mindeps.txt + py3.8: pip-compile --strip-extras -q -U --resolver=backtracking .test-mindeps.in -o py{py_dot_ver}/test-mindeps.txt # The docs requirements are only generated for Python 3.11. - py311: pip-compile --strip-extras -q -U --resolver=backtracking .docs.in -o py{py_dot_ver}/docs.txt + py3.11: pip-compile --strip-extras -q -U --resolver=backtracking .docs.in -o py{py_dot_ver}/docs.txt depends = freezedeps-print [testenv:check-min-python-is-tested] @@ -127,7 +127,7 @@ description = Check the Requires-Python metadata against CI config skip_install = true deps = ruamel.yaml<0.18 - mddj==0.0.6 + mddj==0.0.8 commands = python scripts/ensure_min_python_is_tested.py [testenv:prepare-release]