4
4
push :
5
5
branches :
6
6
- main
7
- paths :
8
- - " **/*.h"
9
- - " **/*.hpp"
10
- - " **/*.c"
11
- - " **/*.cpp"
12
- - " **/*.m"
13
- - " **/*.mm"
14
- - " .github/workflows/lint-clang-formatting.yml"
15
- - " .clang-format"
16
- - " Makefile" # Make commands used for formatting setup
17
- - " Brewfile*" # Tools installation affects formatting environment
18
- - " scripts/ci-diagnostics.sh"
19
7
20
8
pull_request :
21
- paths :
22
- - " **/*.h"
23
- - " **/*.hpp"
24
- - " **/*.c"
25
- - " **/*.cpp"
26
- - " **/*.m"
27
- - " **/*.mm"
28
- - " .github/workflows/lint-clang-formatting.yml"
29
- - " .clang-format"
30
- - " Makefile" # Make commands used for formatting setup
31
- - " Brewfile*" # Tools installation affects formatting environment
32
- - " scripts/ci-diagnostics.sh"
33
9
34
10
# Concurrency configuration:
35
11
# - We use workflow-specific concurrency groups to prevent multiple lint runs on the same code,
@@ -43,10 +19,27 @@ concurrency:
43
19
cancel-in-progress : ${{ github.event_name == 'pull_request' }}
44
20
45
21
jobs :
22
+ files-changed :
23
+ name : Detect File Changes
24
+ runs-on : ubuntu-latest
25
+ outputs :
26
+ run_lint_clang_formatting_for_prs : ${{ steps.changes.outputs.run_lint_clang_formatting_for_prs }}
27
+ steps :
28
+ - uses : actions/checkout@v5
29
+ - name : Get changed files
30
+ id : changes
31
+ uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
32
+ with :
33
+ token : ${{ github.token }}
34
+ filters : .github/file-filters.yml
35
+
46
36
lint :
47
37
# While ubuntu runners have clang-format preinstalled, they use an older version. We want to use the most recent one,
48
38
# that we can easily install locally via brew.
49
39
name : Lint
40
+ # Run the job only for PRs with related changes or non-PR events.
41
+ if : github.event_name != 'pull_request' || needs.files-changed.outputs.run_lint_clang_formatting_for_prs == 'true'
42
+ needs : files-changed
50
43
runs-on : macos-15
51
44
steps :
52
45
- uses : actions/checkout@v5
70
63
- name : Run CI Diagnostics
71
64
if : failure()
72
65
run : ./scripts/ci-diagnostics.sh
66
+
67
+ lint_clang_formatting-required-check :
68
+ needs :
69
+ [
70
+ files-changed,
71
+ lint,
72
+ ]
73
+ name : Lint Clang
74
+ # This is necessary since a failed/skipped dependent job would cause this job to be skipped
75
+ if : always()
76
+ runs-on : ubuntu-latest
77
+ steps :
78
+ # If any jobs we depend on fails gets cancelled or times out, this job will fail.
79
+ # Skipped jobs are not considered failures.
80
+ - name : Check for failures
81
+ if : contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
82
+ run : |
83
+ echo "One of the clang formatting check jobs has failed." && exit 1
0 commit comments