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 cb3613a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/czicompress_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ on:

permissions:
contents: read
pull-requests: read

jobs:
changes:
uses: ./.github/workflows/subproject-changes.yml

build-tests:
needs: changes
if: ${{ needs.changes.outputs.czicompress == 'true' }}
defaults:
run:
working-directory: ${{github.workspace}}/czicompress
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/czicompress_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ permissions:
actions: read
contents: read
security-events: write
pull-requests: read

jobs:
changes:
uses: ./.github/workflows/subproject-changes.yml

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,7 +22,12 @@ on:
permissions: read-all

jobs:
changes:
uses: ./.github/workflows/subproject-changes.yml

analyze:
needs: changes
if: ${{ needs.changes.outputs.czishrink == 'true' }}
name: Analyze CziShrink
defaults:
run:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/czishrink_dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ on:
workflow_dispatch: {}

jobs:
changes:
uses: ./.github/workflows/subproject-changes.yml

build:
needs: changes
if: ${{ needs.changes.outputs.czishrink == 'true' }}
defaults:
run:
working-directory: czishrink
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/subproject-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# 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:
outputs:
czishrink:
description: "'true' if the change affects czishrink or if github.event_name is not 'pull_request'; 'false' otherwise"
value: ${{ jobs.detect_changes.outputs.czishrink }}
czicompress:
description: "'true' if the change affects czicompress or if github.event_name is not 'pull_request'; 'false' otherwise"
value: ${{ jobs.detect_changes.outputs.czicompress }}

jobs:
# JOB to run change detection
detect_changes:
runs-on: ubuntu-latest
# Set job outputs to values from filter step for PRs, and true for other events.
outputs:
czishrink: ${{ steps.result.outputs.czishrink }}
czicompress: ${{ steps.result.outputs.czicompress }}
steps:
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
if: ${{ github.event_name == 'pull_request' }}
id: filter
with:
filters: |
czishrink:
- 'czishrink/**'
- '.github/**'
- '*.yml'
czicompress:
- '**czicompress**'
- '.github/**'
- '*.yml'
- id: result
run: |
echo "czishrink=${{ github.event_name != 'pull_request' || steps.filter.outputs.czishrink == 'true' }}"
echo "czicompress=${{ github.event_name != 'pull_request' || steps.filter.outputs.czicompress == 'true' }}"
echo "czishrink=${{ github.event_name != 'pull_request' || steps.filter.outputs.czishrink == 'true' }}" >> "$GITHUB_OUTPUT"
echo "czicompress=${{ github.event_name != 'pull_request' || steps.filter.outputs.czicompress == 'true' }}" >> "$GITHUB_OUTPUT"

0 comments on commit cb3613a

Please sign in to comment.