From 8fa8d4ecc8d8ad51f6de20154fabf6123a15f1e4 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 | 34 +++++++++++++++++++++++++++++++++- .github/workflows/sterile.yml | 31 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 09758223..d6949daf 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -29,7 +29,39 @@ 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)' + # Ignore any file under .github/, save the current workflow file + - '!(.github/!(workflows/devv.yml))' + build: + needs: [ check_changes ] + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" strategy: fail-fast: false matrix: @@ -139,10 +171,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..a94563e3 100644 --- a/.github/workflows/sterile.yml +++ b/.github/workflows/sterile.yml @@ -18,7 +18,34 @@ 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: + - '!(.github/!(workflows/sterile.yml))' + test: + needs: [ check_changes ] + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" permissions: contents: "read" packages: "read" @@ -137,6 +164,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 +228,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' }}