Skip to content

Commit

Permalink
ci: skip tests if unaffected TASK-1316 (#5295)
Browse files Browse the repository at this point in the history
### 💭 Notes

Trigger PR workflows based on files affected.

The lists of path matchers corresponding to pytest, npm-test, darker are 
in .github/filters.yml.

For a given CI run, the "Detect changed files" step shows a list of files
changed and which filters were matched by them. You can inspect this on
GitHub:

-> Click "Details" on a PR step 
-> Click the "changes" job
-> Expand the "Detect Changed Files" step
-> Expand individual logs to see:
  - list of files changed
  - list of filters triggered

Ideally, these filters always match whenever a PR has any chance of affecting
a job's pass/fail result.

### 👀 Preview steps

1. 🟢 See the "Checks" section of this PR, or screenshots in the description
2. 🟢 Notice the addition of the "ci / changes" job, which runs first and may
  cause pytest, npm-test, or darker to be skipped if no relevant
  files are changed
  • Loading branch information
p2edwards authored Dec 2, 2024
1 parent aaa8aac commit 0711df4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Path filters. Used by workflows/ci.yml to decide which jobs to run.

# If any file changed matches any of the filters in a list, the output for that
# list is set to the string 'true'.

darker:
- '{kpi,kobo,hub}/**/*.py' # .py
- 'pyproject.toml' # rules
- '.github/workflows/darker.yml' # ci

pytest:
- '{kpi,kobo,hub}/**/*.!(md)' # backend
- 'dependencies/**/*.!(md)' # pip
- 'pyproject.toml' # (can affect build/tests)
- '.github/workflows/pytest.yml' # ci

npm-test:
- '{jsapp,test,webpack,static,scripts}/**/*.!(md|py|sh|bash)' # frontend
- '{package*.json,patches/*.patch,scripts/copy_fonts.py}' # npm + postinstall
- '{tsconfig.json,.swcrc,.babelrc*,.browserslistrc}' # compilers
- '{.editorconfig,.prettier*,.stylelint*,.eslint*,coffeelint*}' # linters
- '.gitignore' # (can affect tools)
- '.github/workflows/npm-test.yml' # ci
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ci

on: pull_request

jobs:
changes:
runs-on: ubuntu-latest
permissions: { pull-requests: read }
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
name: Detect changed files
with: { filters: .github/filters.yml }
outputs:
darker: ${{ steps.filter.outputs.darker }}
pytest: ${{ steps.filter.outputs.pytest }}
npm-test: ${{ steps.filter.outputs.npm-test }}

darker:
needs: changes
uses: ./.github/workflows/darker.yml
if: needs.changes.outputs.darker == 'true'

pytest:
needs: changes
uses: ./.github/workflows/pytest.yml
if: needs.changes.outputs.pytest == 'true'

npm-test:
needs: changes
uses: ./.github/workflows/npm-test.yml
if: needs.changes.outputs.npm-test == 'true'
2 changes: 1 addition & 1 deletion .github/workflows/darker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Python linter (Darker)

on: [pull_request]
on: workflow_call
jobs:
darker:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: npm-test
on:
push:
branches: [ main ]
pull_request:
workflow_call:

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: pytest
on:
push:
branches: [ main ]
pull_request:
workflow_call:

jobs:
build:
Expand Down

0 comments on commit 0711df4

Please sign in to comment.