Skip to content

Commit d52c597

Browse files
authored
docs: add a page for other CI systems and fix stale facts (#97)
1 parent 9c6fa4b commit d52c597

9 files changed

Lines changed: 286 additions & 8 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Update versions
2+
3+
on:
4+
schedule:
5+
# Daily check for a new cpp-linter-hooks release
6+
- cron: '20 6 * * *'
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
update:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
# push the update branch and open the pull request
16+
contents: write
17+
pull-requests: write
18+
steps:
19+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
20+
with:
21+
persist-credentials: false
22+
23+
- name: Set the cpp-linter-hooks rev in the examples
24+
run: python3 scripts/update-versions.py
25+
env:
26+
GITHUB_TOKEN: ${{ github.token }}
27+
28+
- name: Create Pull Request
29+
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
sign-commits: true
33+
commit-message: "docs: update the cpp-linter-hooks version in the examples"
34+
branch: auto-update-versions
35+
delete-branch: true
36+
title: "docs: update the cpp-linter-hooks version in the examples"
37+
body: |
38+
Automated update: the `rev:` of the cpp-linter-hooks examples now names the
39+
latest [cpp-linter-hooks release](https://github.com/cpp-linter/cpp-linter-hooks/releases/latest).
40+
labels: |
41+
documentation
42+
assignees: |
43+
${{ github.actor }}

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ pipx run nox -s docs # build into site/
1414
pipx run nox -s docs-live # preview with live reload
1515
```
1616

17+
## Versions in the examples
18+
19+
The [Update versions](https://github.com/cpp-linter/cpp-linter.github.io/actions/workflows/update-versions.yml)
20+
workflow runs daily and opens a pull request when cpp-linter-hooks has a release newer than the
21+
`rev:` in the pages' examples. To do it by hand, run `python3 scripts/update-versions.py`. Blog
22+
posts keep the version of the day they were written.
23+
1724
## Files other projects use
1825

1926
Other repositories load these files from the published site, so do not rename or remove them

‎docs/ai-coding-agents.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ checks on the staged files at each commit, on the agent's machine and on yours:
247247
```yaml title=".pre-commit-config.yaml"
248248
repos:
249249
- repo: https://github.com/cpp-linter/cpp-linter-hooks
250-
rev: v1.8.1
250+
rev: v1.9.0
251251
hooks:
252252
- id: clang-format
253253
args: [--style=file, --version=21]

‎docs/blog/posts/2026-09-12-one-clang-version-everywhere.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ same patch release.
136136

137137
## Containers and other package managers
138138

139-
[Docker images](https://github.com/cpp-linter/clang-tools-docker) carry Ubuntu's clang-format and
140-
clang-tidy packages, tagged by major version up to 22:
139+
[Docker images](https://github.com/cpp-linter/clang-tools-docker) are built from the same static
140+
binaries for LLVM 12 to 23, tagged by major version:
141141

142142
```bash
143143
docker run --rm -v "$PWD":/src xianpengshen/clang-tools:21 clang-format --dry-run --Werror /src/main.cpp

‎docs/getting-started.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pip-install the clang-format and clang-tidy version you pin:
7171
```yaml title=".pre-commit-config.yaml"
7272
repos:
7373
- repo: https://github.com/cpp-linter/cpp-linter-hooks
74-
rev: v1.8.1
74+
rev: v1.9.0
7575
hooks:
7676
- id: clang-format
7777
args: [--style=file, --version=21]
@@ -100,6 +100,8 @@ cpp-linter --version=21 --style=file --tidy-checks=''
100100
- Locally and in other CI, `--files-changed-only` and `--lines-changed-only` read `git diff`;
101101
`--diff-base` sets the commit to compare against. Only on GitHub Actions, which sets
102102
`GITHUB_ACTIONS=true`, do they ask the GitHub API for the changed files.
103+
- [Other CI systems](other-ci.md) has a script and the job definitions for GitLab CI, Jenkins,
104+
Azure Pipelines and Bitbucket Pipelines.
103105

104106
cpp-linter v2, a rewrite in Rust ([cpp-linter-rs](https://github.com/cpp-linter/cpp-linter-rs)),
105107
is in release candidates. Use the Python package until 2.0 is released.
@@ -123,10 +125,12 @@ have, and explains how to check a download.
123125

124126
The static binaries include clang-format, clang-tidy, clang-query, clang-apply-replacements,
125127
clang-include-cleaner (LLVM 18 and later), clang-scan-deps, llvm-cov, llvm-profdata and
126-
llvm-symbolizer. The Docker images carry Ubuntu's clang-format and clang-tidy packages (Debian
127-
unstable's for LLVM 23). The same images are on Docker Hub as `xianpengshen/clang-tools`.
128+
llvm-symbolizer. The Docker images for LLVM 12 to 23 are built from these static binaries, with
129+
clang's builtin headers and the C and C++ standard library headers; the images for 7 to 11 carry
130+
Ubuntu's packages and are no longer rebuilt. The same images are on Docker Hub as
131+
`xianpengshen/clang-tools`.
128132

129133
Single tools are also on PyPI as Python wheels: `clang-format` and `clang-tidy` (the wheels
130134
cpp-linter-hooks installs), [clang-apply-replacements](https://pypi.org/project/clang-apply-replacements/)
131135
(LLVM 16 to 23) and [clang-include-cleaner](https://pypi.org/project/clang-include-cleaner/)
132-
(LLVM 22).
136+
(LLVM 22 and 23).

‎docs/other-ci.md‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
---
2+
title: Other CI systems
3+
description: Run clang-format and clang-tidy on the files a branch changes in GitLab CI, Jenkins, Azure Pipelines and Bitbucket Pipelines, with the cpp-linter command.
4+
hide:
5+
- navigation
6+
---
7+
8+
# Other CI systems
9+
10+
[cpp-linter-action](getting-started.md#on-every-pull-request) is for GitHub Actions. On any other
11+
CI system, run the `cpp-linter` command: it reads `git diff`, checks the C and C++ files your
12+
branch changes with the LLVM version you pin, and writes a report.
13+
14+
What you get outside GitHub:
15+
16+
- The findings in the job log, and a Markdown report in `cpp-linter.md` that the job keeps.
17+
- A failed job when there are findings.
18+
- No comments or reviews on the merge request or pull request. cpp-linter posts those on GitHub
19+
only.
20+
21+
## The script
22+
23+
Save this as `ci/cpp-linter.sh`. It is the same for every CI system; only the job definition
24+
around it differs.
25+
26+
```bash title="ci/cpp-linter.sh"
27+
#!/usr/bin/env bash
28+
# Checks the files this branch changes with clang-format and clang-tidy.
29+
# Usage: ci/cpp-linter.sh <target branch>
30+
set -euo pipefail
31+
32+
target="$1"
33+
llvm=21
34+
35+
python3 -m venv .venv
36+
. .venv/bin/activate
37+
pip install --quiet 'cpp-linter<2' clang-tools
38+
clang-tools install clang-format clang-tidy --version "$llvm" --directory .venv/bin --no-progress-bar
39+
40+
git fetch --quiet origin "+refs/heads/$target:refs/remotes/origin/$target"
41+
base="$(git merge-base "origin/$target" HEAD)"
42+
43+
cpp-linter --version="$llvm" --style=file --tidy-checks='' \
44+
--files-changed-only=true --diff-base="$base" \
45+
--summary-output-file=cpp-linter.md 2>&1 | tee cpp-linter.log
46+
47+
# cpp-linter exits with 0 when it finds problems, so fail the job here.
48+
grep -q ':0 checks-failed$' cpp-linter.log
49+
```
50+
51+
- The script needs Python 3.11 or later, git and a full clone: `git merge-base` cannot find the
52+
point where your branch started in a shallow clone. Each job below turns shallow cloning off.
53+
- `clang-tools` downloads static clang-format and clang-tidy binaries into the virtual
54+
environment, with clang's builtin headers. Nothing is installed outside `.venv`.
55+
- `--style=file` and `--tidy-checks=''` use your `.clang-format` and `.clang-tidy`.
56+
- `--files-changed-only=true` checks every line of the files the branch changes. Add
57+
`--lines-changed-only=true` to report only on the changed lines.
58+
- clang-tidy needs a `compile_commands.json` to find your include paths and flags. Build it
59+
before the script runs and add `--database=build` (the directory that holds it).
60+
- `'cpp-linter<2'` keeps the Python package. Version 2, a rewrite in Rust, is in release
61+
candidates and changes some options.
62+
63+
Run it on your machine first, from a branch of your repository:
64+
65+
```bash
66+
bash ci/cpp-linter.sh main
67+
```
68+
69+
## GitLab CI
70+
71+
```yaml title=".gitlab-ci.yml"
72+
cpp-linter:
73+
image: python:3.13
74+
rules:
75+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
76+
variables:
77+
GIT_DEPTH: 0
78+
script:
79+
- bash ci/cpp-linter.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
80+
artifacts:
81+
when: always
82+
paths:
83+
- cpp-linter.md
84+
```
85+
86+
## Jenkins
87+
88+
For a multibranch pipeline, where Jenkins sets `CHANGE_TARGET` on pull request builds:
89+
90+
```groovy title="Jenkinsfile"
91+
pipeline {
92+
agent { docker { image 'python:3.13' } }
93+
stages {
94+
stage('cpp-linter') {
95+
when { changeRequest() }
96+
steps {
97+
sh 'bash ci/cpp-linter.sh "$CHANGE_TARGET"'
98+
}
99+
}
100+
}
101+
post {
102+
always {
103+
archiveArtifacts artifacts: 'cpp-linter.md', allowEmptyArchive: true
104+
}
105+
}
106+
}
107+
```
108+
109+
## Azure Pipelines
110+
111+
```yaml title="azure-pipelines.yml"
112+
pr:
113+
- main
114+
115+
pool:
116+
vmImage: ubuntu-latest
117+
118+
steps:
119+
- checkout: self
120+
fetchDepth: 0
121+
- task: UsePythonVersion@0
122+
inputs:
123+
versionSpec: '3.13'
124+
- script: bash ci/cpp-linter.sh "$(System.PullRequest.targetBranchName)"
125+
displayName: cpp-linter
126+
condition: eq(variables['Build.Reason'], 'PullRequest')
127+
- publish: cpp-linter.md
128+
artifact: cpp-linter
129+
condition: and(always(), eq(variables['Build.Reason'], 'PullRequest'))
130+
```
131+
132+
The `pr` trigger works for repositories on GitHub and Bitbucket Cloud. For a repository in Azure
133+
Repos, start the pipeline from a branch policy's build validation instead.
134+
135+
## Bitbucket Pipelines
136+
137+
```yaml title="bitbucket-pipelines.yml"
138+
image: python:3.13
139+
140+
clone:
141+
depth: full
142+
143+
pipelines:
144+
pull-requests:
145+
'**':
146+
- step:
147+
name: cpp-linter
148+
script:
149+
- bash ci/cpp-linter.sh "$BITBUCKET_PR_DESTINATION_BRANCH"
150+
artifacts:
151+
- cpp-linter.md
152+
```
153+
154+
## What was tested
155+
156+
The script was run as written, on Linux, with cpp-linter 1.16.0 and LLVM 21: it fails on a branch
157+
with findings and passes on a clean one. The four job definitions use each system's documented
158+
variables for the target branch, but were not run on those systems. If one does not work for
159+
you, [open an issue](https://github.com/cpp-linter/cpp-linter.github.io/issues).
160+
161+
## Only clang-format, without Python
162+
163+
The [Docker images](https://github.com/cpp-linter/clang-tools-docker) hold the clang tools and
164+
nothing else to install. This GitLab job checks the formatting of every source file under `src`:
165+
166+
```yaml title=".gitlab-ci.yml"
167+
clang-format:
168+
image: ghcr.io/cpp-linter/clang-tools:21
169+
script:
170+
- find src -name '*.cpp' -o -name '*.h' | xargs -r clang-format --dry-run --Werror
171+
```

‎docs/why-cpp-linter.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ annotations only; if most of yours come from forks, stay with the split workflow
164164

165165
```yaml title="After"
166166
- repo: https://github.com/cpp-linter/cpp-linter-hooks
167-
rev: v1.8.1
167+
rev: v1.9.0
168168
hooks:
169169
- id: clang-format
170170
args: [--style=file, --version=21]

‎mkdocs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exclude_docs: |
1212
nav:
1313
- Home: index.md
1414
- Get started: getting-started.md
15+
- Other CI: other-ci.md
1516
- AI coding agents: ai-coding-agents.md
1617
- Why cpp-linter: why-cpp-linter.md
1718
- Showcase: showcase.md

‎scripts/update-versions.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
"""Set the cpp-linter-hooks `rev:` in the pages' examples to the latest release.
3+
4+
Usage:
5+
python3 scripts/update-versions.py [tag]
6+
7+
Without a tag, the script asks GitHub for the latest cpp-linter-hooks release.
8+
Blog posts are left alone: each one shows the version of the day it was written.
9+
"""
10+
11+
from __future__ import annotations
12+
13+
import json
14+
import os
15+
import re
16+
import sys
17+
import urllib.request
18+
from pathlib import Path
19+
20+
HOOKS_REPO = "cpp-linter/cpp-linter-hooks"
21+
DOCS = Path(__file__).resolve().parent.parent / "docs"
22+
REV = re.compile(
23+
rf"(repo: https://github\.com/{re.escape(HOOKS_REPO)}\s*\n\s*rev: )v[0-9][0-9.]*"
24+
)
25+
26+
27+
def latest_tag(repo: str) -> str:
28+
request = urllib.request.Request(
29+
f"https://api.github.com/repos/{repo}/releases/latest",
30+
headers={"Accept": "application/vnd.github+json"},
31+
)
32+
token = os.environ.get("GITHUB_TOKEN")
33+
if token:
34+
request.add_header("Authorization", f"Bearer {token}")
35+
with urllib.request.urlopen(request, timeout=30) as response:
36+
return json.load(response)["tag_name"]
37+
38+
39+
def main() -> None:
40+
tag = sys.argv[1] if len(sys.argv) > 1 else latest_tag(HOOKS_REPO)
41+
if not re.fullmatch(r"v[0-9]+\.[0-9]+\.[0-9]+", tag):
42+
sys.exit(f"Unexpected {HOOKS_REPO} tag: {tag!r}")
43+
for page in sorted(DOCS.glob("*.md")):
44+
text = page.read_text(encoding="utf-8")
45+
updated = REV.sub(rf"\g<1>{tag}", text)
46+
if updated != text:
47+
page.write_text(updated, encoding="utf-8")
48+
print(f"{page.name}: rev set to {tag}")
49+
50+
51+
if __name__ == "__main__":
52+
main()

0 commit comments

Comments
 (0)