Skip to content

Commit 9c6fa4b

Browse files
authored
docs(blog): clang-format drift after ubuntu-latest moved to Ubuntu 26.04 (#96)
Before: the blog had nothing on why format checks started failing on unchanged code during the `ubuntu-latest` → Ubuntu 26.04 rollout. After: a new Guides post explains it (the runner's default clang-format went from 18 to 21, and `clang-format-18` isn't preinstalled on 26.04), shows four public projects that hit it, and gives three ways to pin the version (PyPI wheel, cpp-linter-action `version`, cpp-linter-hooks `--version`), plus how to upgrade on purpose. How: one new file, `docs/blog/posts/2026-11-09-ubuntu-26-04-clang-format.md`, in the same front-matter format as the existing posts. Ubuntu package versions were checked on packages.ubuntu.com and the rollout dates on actions/runner-images#14748. `mkdocs build --strict` passes locally. <!-- claude-projects-attribution --> Co-authored-by: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com>
1 parent ace6cca commit 9c6fa4b

1 file changed

Lines changed: 153 additions & 0 deletions

File tree

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
date:
3+
created: 2026-11-09
4+
categories:
5+
- Guides
6+
tags:
7+
- clang-format
8+
- github-actions
9+
- cpp-linter-action
10+
- cpp-linter-hooks
11+
authors:
12+
- shenxianpeng
13+
description: >-
14+
After ubuntu-latest moved to Ubuntu 26.04, the runner's default clang-format went from 18
15+
to 21 and format checks started failing on unchanged code. Pin the version in your repository.
16+
---
17+
18+
# clang-format changed under you: ubuntu-latest is now Ubuntu 26.04
19+
20+
If your clang-format CI check started failing on lines nobody touched, and your workflow says
21+
`runs-on: ubuntu-latest`, the code probably didn't change. The formatter did.
22+
23+
<!-- more -->
24+
25+
## The symptom
26+
27+
A format check that was green for months suddenly reports dozens of violations, usually in
28+
files the pull request never edited:
29+
30+
```text
31+
src/socket_identity.cpp:129:23: error: code should be clang-formatted [-Wclang-format-violations]
32+
```
33+
34+
Or the job doesn't get that far, because a versioned binary it called is gone:
35+
36+
```text
37+
clang-format-18: command not found
38+
```
39+
40+
Nothing in `.clang-format` changed and nobody reformatted anything. The only difference is the
41+
machine the job ran on.
42+
43+
## Why it happens
44+
45+
GitHub is moving the `ubuntu-latest` label from Ubuntu 24.04 to Ubuntu 26.04. The rollout
46+
started on October 19, 2026 and is planned to finish by November 19, 2026
47+
([runner-images#14748](https://github.com/actions/runner-images/issues/14748)). During those
48+
weeks the same workflow can land on either image, so a check can pass on one run and fail on
49+
the next.
50+
51+
The two releases ship different default clang-format versions:
52+
53+
| Ubuntu release | `clang-format` package (default) | Source |
54+
| --- | --- | --- |
55+
| 24.04 (noble) | 18 | [packages.ubuntu.com](https://packages.ubuntu.com/noble/clang-format) |
56+
| 26.04 (resolute) | 21 | [packages.ubuntu.com](https://packages.ubuntu.com/resolute/clang-format) |
57+
58+
clang-format does not promise identical output across major versions, so the same
59+
`.clang-format` file can lay out the same code differently under 21 than under 18. A job that
60+
runs plain `clang-format` (or `apt install clang-format`) quietly picks up the new version.
61+
62+
A job that calls `clang-format-18` breaks in a different way. Ubuntu 26.04 still has a
63+
`clang-format-18` package in its archive, but the 26.04 runner image doesn't preinstall it, so
64+
the command is simply missing.
65+
66+
The root problem is the same in both cases: the formatter version comes from the runner image,
67+
not from your repository.
68+
69+
## It's already happening
70+
71+
In the first weeks of the rollout, several open-source C and C++ projects hit exactly this:
72+
73+
| Project | What happened |
74+
| --- | --- |
75+
| [nnstreamer#5169](https://github.com/nnstreamer/nnstreamer/issues/5169) | The static-checks job installed clang-format from the runner's apt archive with no pin. On 26.04 it jumped from 18 to 21.1.6, and pull requests failed on lines they didn't change. 14 of 149 C++ files would be reformatted. |
76+
| [AntHocNet#848](https://github.com/swarm-routing/AntHocNet/issues/848) | The first try on 26.04 failed with `clang-format-18: command not found` (exit 127). The `.clang-format` file was tuned for 18, so switching versions wasn't an option. |
77+
| [libtmux-cxx#148](https://github.com/libtmux/libtmux-cxx/issues/148) | One of five causes of a red CI on `ubuntu-latest`: the lint job reported 62 lines of `-Wclang-format-violations`, with no code change behind them. |
78+
| [pgagroal#1099](https://github.com/pgagroal/pgagroal/issues/1099) | A related failure: the format check installs from apt.llvm.org, and a short DNS outage there failed the whole pipeline, since every job depends on it. |
79+
80+
The usual first fix is to pin the job back to `runs-on: ubuntu-24.04`. That buys time, but
81+
24.04 will be retired too, and the next image change will bring the same problem back.
82+
83+
## The fix: pin clang-format in your repository
84+
85+
Make the version a line in your repository, so that changing the runner image can't change it.
86+
Pick whichever of these matches how you already run the check.
87+
88+
### Option 1: the PyPI wheel, in any script
89+
90+
clang-format is published on PyPI as a wheel for Linux, macOS and Windows, so one line installs
91+
the exact release on every runner image:
92+
93+
```sh
94+
pip install clang-format==18.1.8
95+
clang-format --version # clang-format version 18.1.8
96+
```
97+
98+
The wheel installs the command as plain `clang-format`, not `clang-format-18`, so scripts that
99+
call the versioned name need a one-word change. It also doesn't depend on apt.llvm.org being
100+
reachable.
101+
102+
### Option 2: cpp-linter-action, in GitHub Actions
103+
104+
[cpp-linter-action](https://github.com/cpp-linter/cpp-linter-action) installs the clang-format
105+
major you ask for itself, so the runner image doesn't matter:
106+
107+
```yaml
108+
- uses: cpp-linter/cpp-linter-action@v2
109+
id: linter
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
with:
113+
version: '18' # the clang-format major your style was tuned for
114+
style: file # use your .clang-format
115+
tidy-checks: '-*' # format check only
116+
- if: steps.linter.outputs.checks-failed > 0
117+
run: exit 1
118+
```
119+
120+
nnstreamer's own `cpp-linter.yml` workflow kept working through the switch for this reason: it
121+
sets the version itself.
122+
123+
### Option 3: cpp-linter-hooks, in pre-commit
124+
125+
If the CI job runs `pre-commit run --all-files`, pin the version in the hook. Contributors then
126+
get the same binary locally too:
127+
128+
```yaml
129+
repos:
130+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
131+
rev: v1.8.4
132+
hooks:
133+
- id: clang-format
134+
args: [--style=file, --version=18]
135+
```
136+
137+
`--version=18` takes the newest 18.x release, and `--version=18.1.8` pins the exact one. For
138+
keeping pre-commit, CI and laptops on the same version, see
139+
[One clang-format version everywhere](2026-09-12-one-clang-version-everywhere.md).
140+
141+
## Moving to a newer clang-format on purpose
142+
143+
Pinning doesn't mean staying on 18 forever. It means upgrading when you decide to, in one pull
144+
request:
145+
146+
1. Bump the pin to the new version (for example `21.1.8`, or `version: '21'`).
147+
2. Reformat the whole tree with that version, in a commit that contains only formatting.
148+
3. Add that commit's hash to `.git-blame-ignore-revs`, so `git blame` skips it.
149+
4. Mention the new version in your contributing guide.
150+
151+
After that, the next runner image change is a non-event for your format check. Use
152+
`ubuntu-latest` or `ubuntu-26.04` for everything else, and let the pin decide which
153+
clang-format runs.

0 commit comments

Comments
 (0)