From 1852515d5870c8f0e90a8b4a286c9d2ccf5f7b54 Mon Sep 17 00:00:00 2001 From: Michael Ekstrand Date: Wed, 3 Jul 2024 18:28:31 -0400 Subject: [PATCH] move path filter into workflow check --- .github/workflows/test.yml | 71 ++++---------------------------------- lkdev/workflows/test.py | 55 +++++------------------------ 2 files changed, 16 insertions(+), 110 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 781330d87..13b23f506 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,50 +3,21 @@ name: Automatic Tests push: branches: - main - pull_request: {} + paths: &id001 + - lenskit/**.py + - '**pyroject.toml' + - requirements*.txt + - data/** + pull_request: + paths: *id001 concurrency: group: test-${{github.ref}} cancel-in-progress: true jobs: - check-changes: - name: Check for changes - runs-on: ubuntu-latest - outputs: - changed: ${{steps.check-for-changes.outputs.changed}} - steps: - - name: 🛒 Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - id: check-for-changes - name: 🔎 Check for changes - run: | - if [[ -z "$PR_NUMBER" ]]; then - echo "not a PR, assuming changed" - echo changed=yes >>"$GITHUB_OUTPUT" - else - if gh pr diff $PR_NUMBER --name-only |grep '^lenskit.*\.py$'; then - echo "source code changed" - echo changed=yes >>"$GITHUB_OUTPUT" - elif gh pr view $PR_NUMBER --json body -t '{{.body}}' | grep 'tests: force'; then - echo "test run forced from PR text" - echo changed=yes >>"$GITHUB_OUTPUT" - else - echo "source code unchanged" - echo changed=no >>"$GITHUB_OUTPUT" - fi - fi - cat $GITHUB_OUTPUT - env: - GH_TOKEN: ${{ github.token }} - PR_NUMBER: ${{ github.event.number }} conda: name: Conda Python ${{matrix.python}} on ${{matrix.platform}} runs-on: ${{matrix.platform}} timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' defaults: run: shell: bash -el {0} @@ -106,9 +77,6 @@ jobs: name: Vanilla Python ${{matrix.python}} on ${{matrix.platform}} runs-on: ${{matrix.platform}} timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' strategy: fail-fast: false matrix: @@ -167,9 +135,6 @@ jobs: name: Non-JIT test coverage runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' steps: - name: 🛒 Checkout uses: actions/checkout@v4 @@ -220,9 +185,6 @@ jobs: name: Minimal dependency tests runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' steps: - name: 🛒 Checkout uses: actions/checkout@v4 @@ -270,9 +232,6 @@ jobs: name: FunkSVD tests on Python ${{matrix.python}} runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' defaults: run: shell: bash -el {0} @@ -328,9 +287,6 @@ jobs: name: Minimal dependency tests for FunkSVD runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' steps: - name: 🛒 Checkout uses: actions/checkout@v4 @@ -378,9 +334,6 @@ jobs: name: Implicit bridge tests on Python ${{matrix.python}} runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' defaults: run: shell: bash -el {0} @@ -436,9 +389,6 @@ jobs: name: Minimal dependency tests for Implicit runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' steps: - name: 🛒 Checkout uses: actions/checkout@v4 @@ -486,9 +436,6 @@ jobs: name: HPF bridge tests on Python ${{matrix.python}} runs-on: ubuntu-latest timeout-minutes: 30 - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' strategy: fail-fast: false matrix: @@ -545,9 +492,6 @@ jobs: defaults: run: shell: bash -el {0} - needs: - - check-changes - if: needs.check-changes.outputs.changed == 'yes' steps: - name: 🛒 Checkout uses: actions/checkout@v4 @@ -654,7 +598,6 @@ jobs: name: Test suite results runs-on: ubuntu-latest needs: - - check-changes - conda - vanilla - nojit diff --git a/lkdev/workflows/test.py b/lkdev/workflows/test.py index 34294bcce..232b86a1c 100644 --- a/lkdev/workflows/test.py +++ b/lkdev/workflows/test.py @@ -9,19 +9,23 @@ META_PYTHON = "3.11" PYTHONS = ["3.10", "3.11", "3.12"] PLATFORMS = ["ubuntu-latest", "macos-latest", "windows-latest"] +FILTER_PATHS = [ + "lenskit/**.py", + "**pyroject.toml", + "requirements*.txt", + "data/**", +] def workflow(): - jobs = {"check-changes": job_check_changes()} + jobs = {} jobs.update(jobs_test_matrix()) jobs["results"] = jobs_result(list(jobs.keys())) return { "name": "Automatic Tests", "on": { - "push": { - "branches": ["main"], - }, - "pull_request": {}, + "push": {"branches": ["main"], "paths": FILTER_PATHS}, + "pull_request": {"paths": FILTER_PATHS}, }, "concurrency": { "group": "test-${{github.ref}}", @@ -279,8 +283,6 @@ def test_job(options: JobOptions) -> GHJob: "name": options.name, "runs-on": options.vm_platform, "timeout-minutes": 30, - "needs": ["check-changes"], - "if": "needs.check-changes.outputs.changed == 'yes'", } if options.env == "conda": job["defaults"] = { @@ -307,8 +309,6 @@ def test_eval_job() -> GHJob: "name": opts.name, "runs-on": opts.vm_platform, "defaults": {"run": {"shell": "bash -el {0}"}}, - "needs": ["check-changes"], - "if": "needs.check-changes.outputs.changed == 'yes'", "steps": [step_checkout(opts)] + steps_setup_conda(opts) + steps_mldata(opts, ["ml-100k", "ml-20m"]) @@ -352,43 +352,6 @@ def test_doc_job() -> GHJob: } -def job_check_changes() -> GHJob: - return { - "name": "Check for changes", - "runs-on": "ubuntu-latest", - "outputs": {"changed": "${{steps.check-for-changes.outputs.changed}}"}, - "steps": [ - step_checkout(), - { - "id": "check-for-changes", - "name": "🔎 Check for changes", - "run": script(""" - if [[ -z "$PR_NUMBER" ]]; then - echo "not a PR, assuming changed" - echo changed=yes >>"$GITHUB_OUTPUT" - else - if gh pr diff $PR_NUMBER --name-only |grep '^lenskit.*\\.py$'; then - echo "source code changed" - echo changed=yes >>"$GITHUB_OUTPUT" - elif gh pr view $PR_NUMBER --json body -t '{{.body}}' | grep 'tests: force'; then - echo "test run forced from PR text" - echo changed=yes >>"$GITHUB_OUTPUT" - else - echo "source code unchanged" - echo changed=no >>"$GITHUB_OUTPUT" - fi - fi - cat $GITHUB_OUTPUT - """), # noqa: E501 - "env": { - "GH_TOKEN": "${{ github.token }}", - "PR_NUMBER": "${{ github.event.number }}", - }, - }, - ], - } - - def jobs_test_matrix() -> dict[str, GHJob]: return { "conda": test_job(