From c2a32d4269715e71c8872d571c9306070081a821 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 | 31 +++++++++++++++++++++++++++++++ .github/workflows/sterile.yml | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 09758223..3021aedc 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: "false" + 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 }}" + filters: | + devfiles: + - '**/**' + - '!README.md' + - '!LICENSE' + - '!design-docs/**' + - '!.gitignore' + - '!.github/**' + - '.github/workflows/dev.yml' + build: + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" strategy: fail-fast: false matrix: diff --git a/.github/workflows/sterile.yml b/.github/workflows/sterile.yml index b0dd1b12..22a82df5 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: "false" + 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 }}" + filters: | + devfiles: + - '**/**' + - '!README.md' + - '!LICENSE' + - '!design-docs/**' + - '!.gitignore' + - '!.github/**' + - '.github/workflows/sterile.yml' + test: + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" permissions: contents: "read" packages: "read" @@ -137,6 +168,7 @@ jobs: limit-access-to-actor: true push: + if: "${{ needs.check_changes.outputs.devfiles == 'true' }}" permissions: contents: "read" packages: "write"