Skip to content

Commit

Permalink
only run tests if test code is changed
Browse files Browse the repository at this point in the history
mdekstrand committed Jul 2, 2024
1 parent 134a54c commit 7da11a7
Showing 3 changed files with 74 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -8,10 +8,31 @@ 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
run: |
gh pr diff --name-only |grep '^lenskit.*\.py$'
if [ "$?" -eq 0 ]; then
echo changed=true >>$GITHUB_OUTPUT
else
echo changed=false >>$GITHUB_OUTPUT
fi
conda:
name: Conda Python ${{matrix.python}} on ${{matrix.platform}}
runs-on: ${{matrix.platform}}
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
defaults:
run:
shell: bash -el {0}
@@ -71,6 +92,9 @@ jobs:
name: Vanilla Python ${{matrix.python}} on ${{matrix.platform}}
runs-on: ${{matrix.platform}}
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
strategy:
fail-fast: false
matrix:
@@ -129,6 +153,9 @@ jobs:
name: Non-JIT test coverage
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
steps:
- name: 🛒 Checkout
uses: actions/checkout@v4
@@ -179,6 +206,9 @@ jobs:
name: Minimal dependency tests
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
steps:
- name: 🛒 Checkout
uses: actions/checkout@v4
@@ -226,6 +256,9 @@ jobs:
name: FunkSVD tests on Python ${{matrix.python}}
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
defaults:
run:
shell: bash -el {0}
@@ -281,6 +314,9 @@ jobs:
name: Minimal dependency tests for FunkSVD
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
steps:
- name: 🛒 Checkout
uses: actions/checkout@v4
@@ -328,6 +364,9 @@ jobs:
name: Implicit bridge tests on Python ${{matrix.python}}
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
defaults:
run:
shell: bash -el {0}
@@ -383,6 +422,9 @@ jobs:
name: Minimal dependency tests for Implicit
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
steps:
- name: 🛒 Checkout
uses: actions/checkout@v4
@@ -430,6 +472,9 @@ jobs:
name: HPF bridge tests on Python ${{matrix.python}}
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- check-changes
if: jobs.check-changes.outputs.changed
strategy:
fail-fast: false
matrix:
@@ -592,6 +637,7 @@ jobs:
name: Test suite results
runs-on: ubuntu-latest
needs:
- check-changes
- conda
- vanilla
- nojit
2 changes: 2 additions & 0 deletions lkdev/ghactions.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ def command(cls, args: list[str]):
{
"name": str,
"runs-on": str,
"if": NotRequired[str],
"outputs": NotRequired[dict[str, str]],
"timeout-minutes": NotRequired[int],
"strategy": NotRequired[dict[str, Any]],
"defaults": NotRequired[dict[str, Any]],
27 changes: 26 additions & 1 deletion lkdev/workflows/test.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@


def workflow():
jobs: dict[str, GHJob] = jobs_test_matrix()
jobs = {"check-changes": job_check_changes()}
jobs.update(jobs_test_matrix())
jobs["results"] = jobs_result(list(jobs.keys()))
return {
"name": "Automatic Tests",
@@ -286,6 +287,8 @@ def test_job(options: JobOptions) -> GHJob:
"name": options.name,
"runs-on": options.vm_platform,
"timeout-minutes": 30,
"needs": ["check-changes"],
"if": "jobs.check-changes.outputs.changed",
}
if options.env == "conda":
job["defaults"] = {
@@ -355,6 +358,28 @@ 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",
"run": script("""
gh pr diff --name-only |grep '^lenskit.*\\.py$'
if [ "$?" -eq 0 ]; then
echo changed=true >>$GITHUB_OUTPUT
else
echo changed=false >>$GITHUB_OUTPUT
fi
"""),
},
],
}


def jobs_test_matrix() -> dict[str, GHJob]:
return {
"conda": test_job(

0 comments on commit 7da11a7

Please sign in to comment.