You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7341d88
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/blog/posts/2026-09-20-clang-tidy-pull-requests-github-actions.md
+10-13Lines changed: 10 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,13 +22,12 @@ get stuck: clang-tidy needs the real compile flags or it reports missing headers
22
22
an existing code base produces thousands of findings nobody asked for, and the output ends up in a
23
23
CI log that contributors do not open.
24
24
25
-
This guide sets up one GitHub Actions job that solves those three problems. When it is done,
26
-
clang-tidy findings appear as review comments on the lines a pull request changed, and the check
27
-
turns red when something is left unfixed.
25
+
With the GitHub Actions job below, clang-tidy findings appear as review comments on the lines a
26
+
pull request changed, and the check turns red when something is left unfixed.
28
27
29
28
<!-- more -->
30
29
31
-
## Step 1: start with a small `.clang-tidy`
30
+
## Step 1: Start with a small `.clang-tidy`
32
31
33
32
Put the configuration in the repository, not in the workflow. The same file is then used by CI,
34
33
by editors (clangd, CLion, Qt Creator, Visual Studio) and by anyone running clang-tidy by hand.
@@ -63,7 +62,7 @@ $ clang-tidy --verify-config
63
62
No config errors detected.
64
63
```
65
64
66
-
## Step 2: generate `compile_commands.json`
65
+
## Step 2: Generate `compile_commands.json`
67
66
68
67
clang-tidy parses each file the way the compiler does, so it needs the include paths, defines and
69
68
language standard of the real build. It reads them from a compilation database,
@@ -113,7 +112,7 @@ Two things commonly go wrong here:
113
112
- **Generated headers.** Protobuf output, `config.h` and similar files only exist after the build
114
113
step that produces them. Build those targets before running clang-tidy.
115
114
116
-
## Step 3: add the workflow
115
+
## Step 3: Add the workflow
117
116
118
117
```yaml title=".github/workflows/clang-tidy.yml"
119
118
name: clang-tidy
@@ -155,15 +154,13 @@ jobs:
155
154
| --- | --- |
156
155
| `version: '21'` | Installs clang-tidy 21 on the runner. Pin it, and use the same major version locally; new LLVM releases add and move checks. |
157
156
| `style: ''` | Turns clang-format off, so this job is clang-tidy only. Set it to `file` to check formatting against your `.clang-format` in the same step. |
158
-
| `tidy-checks: ''` | Uses your `.clang-tidy` and nothing else. The default value is a broad list of check groups that is **appended** to the `Checks` in your file, which is the usual reason CI reports more than a local run. |
157
+
| `tidy-checks: ''` | Uses your `.clang-tidy` and nothing else. The default value is a broad list of check groups that is appended to the `Checks` in your file, so CI reports more than a local run with the same `.clang-tidy`. |
159
158
| `database: build` | The directory that contains `compile_commands.json`. |
160
159
| `lines-changed-only: true` | Reports findings only on lines the pull request added or modified. |
161
160
| `tidy-review: true` | Posts the findings as a pull request review. |
162
161
| `step-summary: true` | Writes the same report to the workflow run's summary page. |
163
162
164
-
## Step 4: report only what the pull request changed
165
-
166
-
This is the setting that makes clang-tidy acceptable on a code base that has never used it.
163
+
## Step 4: Report only what the pull request changed
167
164
168
165
- `files-changed-only` defaults to `true`: only files touched by the pull request are analyzed.
169
166
- `lines-changed-only` filters what is reported inside those files:
@@ -182,7 +179,7 @@ base gets cleaner in the places that are actively worked on, and nobody has to l
182
179
clang-tidy still parses the whole translation unit, so the run time depends on how many files
183
180
changed, not on how many lines.
184
181
185
-
## Step 5: choose where the feedback appears
182
+
## Step 5: Choose where the feedback appears
186
183
187
184
| Feedback | Input | Default | Token permission |
188
185
| --- | --- | --- | --- |
@@ -207,7 +204,7 @@ Things to know about reviews:
207
204
Approving requires the repository setting "Allow GitHub Actions to create and approve pull
208
205
requests". Set `passive-reviews: true` if the bot should only comment.
209
206
210
-
## Step 6: decide when the check fails
207
+
## Step 6: Decide when the check fails
211
208
212
209
The action reports; it does not fail the job by itself. The last step in the workflow does that,
213
210
using the `clang-tidy-checks-failed` output (there is also `clang-format-checks-failed`, and
@@ -237,7 +234,7 @@ arbitrary code execution for anyone who opens a pull request.
237
234
| Nothing is reported for headers | `HeaderFilterRegex` does not match your header paths. |
238
235
| Findings from vendored code | Narrow `HeaderFilterRegex`, and exclude the sources with `ignore: 'third_party|build'`. |
239
236
| No review shows up | The pull request is a draft, comes from a fork, or the job lacks `pull-requests: write`. |
240
-
| The job is slow | Keep `files-changed-only` on. The analysis already uses every core (`jobs: 0`); the time usually goes into installing dependencies and configuring, so cache those. |
237
+
| The job is slow | Keep `files-changed-only` on. The analysis already uses every core (`jobs: 0`). Check the step timings in the run; if installing dependencies or configuring takes longer than the analysis, cache those. |
0 commit comments