From cf33220e26b015c9dae4ff0e98de7a82195b7206 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Mon, 11 Nov 2024 15:53:44 +0000 Subject: [PATCH] ci: Skip dev.yml, sterile.yml if there are no code changes 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 --- .github/workflows/dev.yml | 33 ++++++++++++++++++++++++++++++++- .github/workflows/sterile.yml | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 09758223..3bc0fb60 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -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: @@ -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' }} diff --git a/.github/workflows/sterile.yml b/.github/workflows/sterile.yml index b0dd1b12..dd4ee2f0 100644 --- a/.github/workflows/sterile.yml +++ b/.github/workflows/sterile.yml @@ -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" @@ -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" @@ -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' }}