From c68a8c4f84e48c15e47b02cfb056848a4ac49f67 Mon Sep 17 00:00:00 2001 From: Phil Edwards Date: Sat, 23 Nov 2024 02:40:12 -0500 Subject: [PATCH] wip - ci: skip tests if unaffected --- .github/filters.yml | 33 ++++++++++++++++++++++++++++ .github/workflows/changes.yml | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/filters.yml create mode 100644 .github/workflows/changes.yml diff --git a/.github/filters.yml b/.github/filters.yml new file mode 100644 index 0000000000..559acc320a --- /dev/null +++ b/.github/filters.yml @@ -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))' diff --git a/.github/workflows/changes.yml b/.github/workflows/changes.yml new file mode 100644 index 0000000000..9db25fc334 --- /dev/null +++ b/.github/workflows/changes.yml @@ -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'