Skip to content

Commit

Permalink
wip - ci: skip tests if unaffected
Browse files Browse the repository at this point in the history
  • Loading branch information
p2edwards committed Nov 23, 2024
1 parent 79e33e8 commit c68a8c4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Part of .github/workflows/changes.yml, separated for better syntax highlighting
# > "If a new PR is opened,
# > and it only changes 1 file, which test(s) should be re-run?"

should-run-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

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

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

new-files-at-root-level:
# New and unrecognized files can affect CI test results.
# - We usually want to err on the side of running tests
# instead of skipping them.
# - This filter is basically an inverted 'ignore' list of paths
# we know about already.
# - Add new entries into this list once they're accounted for
# in the other lists.
# (alphabetical order, folders-first)
- '!(((\.github|\.storybook|\.tx|cypress|dependencies|docker|hub|jsapp|kobo|kpi|patches|scripts|static|test|webpack)/**)|(\.babelrc\.json|\.browserslistrc|\.coveragerc|\.dockerignore|\.editorconfig|\.eslintignore|\.eslintrc\.js|\.git-blame-ignore-revs|\.gitattributes|\.gitignore|\.gitlab-ci\.yml|\.gitmodules|\.node-version|\.nvmrc|\.prettierrc\.js|\.stylelintrc\.js|\.swcrc|CONTRIBUTING\.md|Dockerfile|LICENSE|README\.md|coffeelint\.json|dependabot\.yml|format-python\.sh|kpi\.code-workspace|locale|manage\.py|package-lock\.json|package\.json|pip-compile\.sh|pyproject\.toml|tsconfig\.json))'
41 changes: 41 additions & 0 deletions .github/workflows/changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: changes

on:
push:
branches: [ main ]
pull_request:

jobs:
changes:
name: Detect files changed

runs-on: ubuntu-latest
permissions:
pull-requests: read

outputs:
npm-test: ${{ steps.filter.outputs.should-run-npm-test }}
pytest: ${{ steps.filter.outputs.should-run-pytest }}
darker: ${{ steps.filter.outputs.should-run-darker }}

steps:
- name: Checkout source code (merge ref)
uses: actions/checkout@v4

- id: filter
name: Detect files changed
uses: dorny/paths-filter@v3
with:
filters: .github/filters.yml

# echoing (for testing purposes)
- if: steps.filter.outputs.npm-test
run: echo 'frontend files changed; should run npm-test.yml'\
- if: steps.filter.outputs.pytest
run: echo 'backend files changed; should run pytest.yml'
- if: steps.filter.outputs.darker
run: echo 'python files changed; should run darker.yml'
- if: steps.filter.outputs.ci
run: echo 'selective ci filtering updated'
- if: steps.filter.outputs.new-unknown-files:
run: echo 'unlisted files changed; will likely run pytest and npm-test'

0 comments on commit c68a8c4

Please sign in to comment.