Skip to content

Commit db5351b

Browse files
aborgna-qcqc-alec
andauthored
ci: Move change filter to composable action (#985)
Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
1 parent 6a225cc commit db5351b

File tree

3 files changed

+64
-48
lines changed

3 files changed

+64
-48
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Detect changed files.
2+
description: Checks if any relevant files have changed in the current pull request or commit. Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
3+
4+
# The file filters are defined in `.github/change-filters.yml`.
5+
#
6+
# Requires
7+
# ```
8+
# permissions:
9+
# pull-requests: read
10+
# ```
11+
12+
# Set job outputs to values from filter step
13+
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label.
14+
outputs:
15+
extensions:
16+
description: "The extension definitions have changed"
17+
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.std-extensions == 'true' }}
18+
rust:
19+
description: "Rust files have changed"
20+
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.rust == 'true' }}
21+
rust-core:
22+
description: "The main tket rust library has changed"
23+
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.rust == 'true' }}
24+
python:
25+
description: "Python files have changed"
26+
value: ${{ steps.override.outputs.out == 'true' || steps.change-filters.outputs.python == 'true' }}
27+
28+
runs:
29+
using: composite
30+
# Check if changes were made to the relevant files.
31+
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
32+
steps:
33+
- name: Override label
34+
shell: bash
35+
id: override
36+
run: |
37+
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
38+
if [ "$OVERRIDE_LABEL" == "true" ]; then
39+
echo "Overriding due to label 'run-ci-checks'"
40+
echo "out=true" >> $GITHUB_OUTPUT
41+
elif [ "$DEFAULT_BRANCH" == "true" ]; then
42+
echo "Overriding due to running on the default branch"
43+
echo "out=true" >> $GITHUB_OUTPUT
44+
fi
45+
env:
46+
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}
47+
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
48+
- if: steps.override.outputs.out != 'true'
49+
uses: dorny/paths-filter@v3
50+
id: change-filters
51+
with:
52+
filters: .github/change-filters.yml

.github/workflows/ci.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,16 @@ jobs:
3838
changes:
3939
name: Check for changes
4040
runs-on: ubuntu-latest
41-
# Required permissions
4241
permissions:
4342
pull-requests: read
44-
# Set job outputs to values from filter step
45-
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label.
4643
outputs:
47-
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
48-
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
49-
extensions: ${{ steps.filter.outputs.extensions == 'true' || steps.override.outputs.out == 'true' }}
44+
rust: ${{ steps.filter.outputs.rust }}
45+
python: ${{ steps.filter.outputs.python }}
46+
extensions: ${{ steps.filter.outputs.llvm }}
5047
steps:
51-
- uses: actions/checkout@v4
52-
- name: Override label
53-
id: override
54-
run: |
55-
echo "Labels: ${{ github.event.pull_request.labels.*.name }}"
56-
echo "Label contains run-ci-checks: ${{ contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}"
57-
if [ "${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}" == "true" ]; then
58-
echo "Overriding due to label 'run-ci-checks'"
59-
echo "out=true" >> $GITHUB_OUTPUT
60-
elif [ "${{ github.ref_name == github.event.repository.default_branch }}" == "true" ]; then
61-
echo "Overriding due to running on the default branch"
62-
echo "out=true" >> $GITHUB_OUTPUT
63-
fi
64-
- uses: dorny/paths-filter@v3
65-
id: filter
66-
with:
67-
filters: .github/change-filters.yml
48+
- uses: actions/checkout@v4
49+
- uses: ./.github/actions/check-changes
50+
id: filter
6851

6952
check-rs:
7053
name: Check Rust code 🦀

.github/workflows/semver-checks.yml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,19 @@ on:
66

77
jobs:
88
# Check if changes were made to the relevant files.
9-
# Always returns true if running on the default branch, to ensure all changes are throughly checked.
9+
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
1010
changes:
1111
name: Check for changes
1212
runs-on: ubuntu-latest
13-
# Required permissions
1413
permissions:
1514
pull-requests: read
16-
# Set job outputs to values from filter step
17-
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label.
1815
outputs:
19-
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
20-
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
16+
rust: ${{ steps.filter.outputs.rust }}
17+
python: ${{ steps.filter.outputs.python }}
2118
steps:
22-
- uses: actions/checkout@v4
23-
- name: Override label
24-
id: override
25-
run: |
26-
echo "Label contains run-ci-checks: $OVERRIDE_LABEL"
27-
if [ "$OVERRIDE_LABEL" == "true" ]; then
28-
echo "Overriding due to label 'run-ci-checks'"
29-
echo "out=true" >> $GITHUB_OUTPUT
30-
elif [ "$DEFAULT_BRANCH" == "true" ]; then
31-
echo "Overriding due to running on the default branch"
32-
echo "out=true" >> $GITHUB_OUTPUT
33-
fi
34-
env:
35-
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }}
36-
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }}
37-
- uses: dorny/paths-filter@v3
38-
id: filter
39-
with:
40-
filters: .github/change-filters.yml
19+
- uses: actions/checkout@v4
20+
- uses: ./.github/actions/check-changes
21+
id: filter
4122

4223
rs-semver-checks:
4324
needs: [changes]

0 commit comments

Comments
 (0)