Skip to content

Commit

Permalink
ci: Skip dev.yml, sterile.yml if there are no code changes
Browse files Browse the repository at this point in the history
Skip dev.yml and sterile.yml workflows if there are no relevant code
change. This means we skip the main jobs if the only files changed in
the PR are README.md, LICENSE, .gitignore, anything under design-docs,
or anything under .github and apart from the definition of the workflow
itself.

Signed-off-by: Quentin Monnet <[email protected]>
  • Loading branch information
qmonnet committed Nov 11, 2024
1 parent f86c306 commit cf33220
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,38 @@ permissions:
id-token: "write"

jobs:
check_changes:
name: "Deduce required tests from code changes"
runs-on: "ubuntu-latest"
outputs:
devfiles: "${{ steps.changes.outputs.devfiles }}"
steps:
- name: "Checkout"
if: "${{ !github.event.pull_request }}"
uses: "actions/checkout@v4"
with:
persist-credentials: "true"
fetch-depth: "0"
- name: "Check code changes"
uses: "dorny/paths-filter@v3"
id: "changes"
with:
# For "push" events, compare against the "ref" base branch.
# For "pull_request" events, this is ignored and will compare against
# the pull request base branch.
base: "${{ github.ref }}"
predicate-quantifier: 'every'
filters: |
devfiles:
- '!(README.md)'
- '!(LICENSE)'
- '!(design-docs/**)'
- '!(.gitignore)'
- '!(.github/!(workflows/devv.yml))'
build:
needs: [ check_changes ]
if: "${{ needs.check_changes.outputs.devfiles == 'true' }}"
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -139,10 +170,10 @@ jobs:

summary:
name: "summary"
if: ${{ always() }}
runs-on: "ubuntu-latest"
needs:
- build
if: ${{ always() && needs.build.result != 'skipped' }}
steps:
- name: "Flag any build matrix failures"
if: ${{ needs.build.result != 'success' }}
Expand Down
35 changes: 34 additions & 1 deletion .github/workflows/sterile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,38 @@ concurrency:
cancel-in-progress: true

jobs:
check_changes:
name: "Deduce required tests from code changes"
runs-on: "ubuntu-latest"
outputs:
devfiles: "${{ steps.changes.outputs.devfiles }}"
steps:
- name: "Checkout"
if: "${{ !github.event.pull_request }}"
uses: "actions/checkout@v4"
with:
persist-credentials: "true"
fetch-depth: "0"
- name: "Check code changes"
uses: "dorny/paths-filter@v3"
id: "changes"
with:
# For "push" events, compare against the "ref" base branch.
# For "pull_request" events, this is ignored and will compare against
# the pull request base branch.
base: "${{ github.ref }}"
predicate-quantifier: 'every'
filters: |
devfiles:
- '!(README.md)'
- '!(LICENSE)'
- '!(design-docs/**)'
- '!(.gitignore)'
- '!(.github/!(workflows/sterile.yml))'
test:
needs: [ check_changes ]
if: "${{ needs.check_changes.outputs.devfiles == 'true' }}"
permissions:
contents: "read"
packages: "read"
Expand Down Expand Up @@ -137,6 +168,8 @@ jobs:
limit-access-to-actor: true

push:
needs: [ check_changes ]
if: "${{ needs.check_changes.outputs.devfiles == 'true' }}"
permissions:
contents: "read"
packages: "write"
Expand Down Expand Up @@ -199,11 +232,11 @@ jobs:

summary:
name: "summary"
if: ${{ always() }}
runs-on: "ubuntu-latest"
needs:
- test
- push
if: ${{ always() && needs.test.result != 'skipped' && needs.push.result != 'skipped' }}
steps:
- name: "Flag any test failures"
if: ${{ needs.test.result != 'success' }}
Expand Down

0 comments on commit cf33220

Please sign in to comment.