From cfe961d82f527d54a05ad2fbb38881791ebd421e Mon Sep 17 00:00:00 2001 From: "Ringler, Moritz" Date: Wed, 22 Nov 2023 17:22:03 +0100 Subject: [PATCH] Add path-filtering for PRs --- .github/workflows/czicompress_cmake.yml | 7 ++++ .github/workflows/czicompress_codeql.yml | 7 ++++ .github/workflows/czishrink_codeql.yml | 5 +++ .github/workflows/czishrink_dotnet.yml | 7 ++++ .github/workflows/subproject-changes.yml | 49 ++++++++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 .github/workflows/subproject-changes.yml diff --git a/.github/workflows/czicompress_cmake.yml b/.github/workflows/czicompress_cmake.yml index 485c9a0..f760563 100644 --- a/.github/workflows/czicompress_cmake.yml +++ b/.github/workflows/czicompress_cmake.yml @@ -12,7 +12,14 @@ permissions: contents: read jobs: + changes: + uses: ./.github/workflows/subproject-changes.yml + with: + event_name: ${{ github.event_name }} + build-tests: + needs: changes + if: ${{ needs.changes.outputs.czicompress }} defaults: run: working-directory: ${{github.workspace}}/czicompress diff --git a/.github/workflows/czicompress_codeql.yml b/.github/workflows/czicompress_codeql.yml index dcad435..e3cbb3f 100644 --- a/.github/workflows/czicompress_codeql.yml +++ b/.github/workflows/czicompress_codeql.yml @@ -16,7 +16,14 @@ permissions: security-events: write jobs: + changes: + uses: ./.github/workflows/subproject-changes.yml + with: + event_name: ${{ github.event_name }} + analyze: + needs: changes + if: ${{ needs.changes.outputs.czicompress == 'true' }} name: Analyze CPP defaults: run: diff --git a/.github/workflows/czishrink_codeql.yml b/.github/workflows/czishrink_codeql.yml index d1dc728..42c98cd 100644 --- a/.github/workflows/czishrink_codeql.yml +++ b/.github/workflows/czishrink_codeql.yml @@ -22,6 +22,11 @@ on: permissions: read-all jobs: + changes: + uses: ./.github/workflows/subproject-changes.yml + with: + event_name: ${{ github.event_name }} + analyze: name: Analyze CziShrink defaults: diff --git a/.github/workflows/czishrink_dotnet.yml b/.github/workflows/czishrink_dotnet.yml index 476b920..70a0a34 100644 --- a/.github/workflows/czishrink_dotnet.yml +++ b/.github/workflows/czishrink_dotnet.yml @@ -15,7 +15,14 @@ on: workflow_dispatch: {} jobs: + changes: + uses: ./.github/workflows/subproject-changes.yml + with: + event_name: ${{ github.event_name }} + build: + needs: changes + if: ${{ needs.changes.outputs.czishrink }} defaults: run: working-directory: czishrink diff --git a/.github/workflows/subproject-changes.yml b/.github/workflows/subproject-changes.yml new file mode 100644 index 0000000..c518cf7 --- /dev/null +++ b/.github/workflows/subproject-changes.yml @@ -0,0 +1,49 @@ +--- +# A reusable workflow that is used to detect whether code changes +# are relevant for czishrink and/or czicompress. +# See +# - https://github.com/dorny/paths-filter#examples +# - https://docs.github.com/en/actions/using-workflows/reusing-workflows +name: subproject-changes + +# Required permissions +permissions: + pull-requests: read + +on: + workflow_call: + inputs: + event_name: + required: true + type: string + outputs: + czishrink: + description: "true if the change affects czishrink or if event_name is not 'pull_request'; false otherwise" + value: ${{ inputs.event_name != 'pull_request' || jobs.changes.outputs.czishrink == 'true' }} + czicompress: + description: "true if the change affects czicompress or if event_name is not 'pull_request'; false otherwise" + value: ${{ inputs.event_name != 'pull_request' || jobs.changes.outputs.czishrink == 'true' }} + +jobs: + # JOB to run change detection + changes: + if: ${{ inputs.event_name == 'pull_request' }} + runs-on: ubuntu-latest + # Set job outputs to values from filter step + outputs: + czishrink: ${{ steps.filter.outputs.czishrink }} + czicompress: ${{ steps.filter.outputs.czicompress }} + steps: + # For pull requests it's not necessary to checkout the code + - uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + czishrink: + - 'czishrink/**' + - '.github/**' + - '*.yml' + czicompress: + - '**czicompress**' + - '.github/**' + - '*.yml'