From 0545eaa8a699bbd97caabf89205501c374722732 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 | 35 ++++++++++++++++++++++++++++++++++- .github/workflows/sterile.yml | 32 +++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 09758223..44999910 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -29,7 +29,40 @@ 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.0.2" + 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 +172,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..f79a18f7 100644 --- a/.github/workflows/sterile.yml +++ b/.github/workflows/sterile.yml @@ -18,7 +18,35 @@ 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.0.2" + 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: + - '!(.gitignore)' + - '!(.github/!(workflows/sterile.yml))' + test: + needs: [ check_changes ] + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" permissions: contents: "read" packages: "read" @@ -137,6 +165,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 +229,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' }}