Skip to content

Commit

Permalink
move path filter into workflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jul 3, 2024
1 parent 679f561 commit 1852515
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 110 deletions.
71 changes: 7 additions & 64 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -654,7 +598,6 @@ jobs:
name: Test suite results
runs-on: ubuntu-latest
needs:
- check-changes
- conda
- vanilla
- nojit
Expand Down
55 changes: 9 additions & 46 deletions lkdev/workflows/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down Expand Up @@ -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"] = {
Expand All @@ -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"])
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1852515

Please sign in to comment.