Skip to content

Commit d1c0538

Browse files
authored
chore(ci): Add required checks job for lint clang formatting (#6004)
1 parent 83d27f6 commit d1c0538

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

.github/file-filters.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ run_api_stability_for_prs: &run_api_stability_for_prs # API-related code
6565
- "sdk_api.json"
6666
- "sdk_api_v9.json"
6767

68+
run_lint_clang_formatting_for_prs: &run_lint_clang_formatting_for_prs
69+
- "**/*.h"
70+
- "**/*.hpp"
71+
- "**/*.c"
72+
- "**/*.cpp"
73+
- "**/*.m"
74+
- "**/*.mm"
75+
76+
# GH Actions
77+
- ".github/workflows/lint-clang-formatting.yml"
78+
- ".github/file-filters.yml"
79+
80+
# Formatting
81+
- ".clang-format"
82+
# Other
83+
- "Makefile" # Make commands used for formatting setup
84+
- "Brewfile*" # Tools installation affects formatting environment
85+
- "scripts/ci-diagnostics.sh" # CI diagnostics may affect formatting checks
86+
6887
run_objc_conversion_analysis_for_prs: &run_objc_conversion_analysis_for_prs
6988
- "SwiftConversion/**"
7089

.github/workflows/lint-clang-formatting.yml

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,8 @@ on:
44
push:
55
branches:
66
- 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"
197

208
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"
339

3410
# Concurrency configuration:
3511
# - We use workflow-specific concurrency groups to prevent multiple lint runs on the same code,
@@ -43,10 +19,27 @@ concurrency:
4319
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
4420

4521
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+
4636
lint:
4737
# While ubuntu runners have clang-format preinstalled, they use an older version. We want to use the most recent one,
4838
# that we can easily install locally via brew.
4939
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
5043
runs-on: macos-15
5144
steps:
5245
- uses: actions/checkout@v5
@@ -70,3 +63,21 @@ jobs:
7063
- name: Run CI Diagnostics
7164
if: failure()
7265
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

Comments
 (0)