Skip to content

Commit

Permalink
Add path-filtering for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ringler committed Nov 23, 2023
1 parent 41bac9f commit cfe961d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/czicompress_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/czicompress_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/czishrink_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/czishrink_dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/subproject-changes.yml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit cfe961d

Please sign in to comment.