Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 4 additions & 38 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,11 @@ on:
- "main"
workflow_dispatch:

permissions: {}

jobs:
draft-release:
permissions:
# write permission is required to create a github release
contents: write
# write permission is required for autolabeler
# otherwise, read permission is required at least
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Generate release notes header
run: |
{
echo "## 💡 Default Clang Tool Versions"
echo ""
echo "Versions are resolved dynamically from PyPI at hook runtime, always using the latest stable release by default. "
echo "You can pin a specific version by adding the \`--version\` argument under \`args\` in your pre-commit config."
echo "See [Custom Clang Tool Version](https://github.com/cpp-linter/cpp-linter-hooks?tab=readme-ov-file#custom-clang-tool-version) for details."
echo ""
} > release_notes.md
cat release_notes.md

# Export release notes content to env variable for Release Drafter
{
echo "RELEASE_BODY<<EOF"
cat release_notes.md
echo "EOF"
} >> "$GITHUB_ENV"

# Draft your next Release notes as Pull Requests are merged into the default branch
- uses: release-drafter/release-drafter@978bb0b30c5ee8cdd332ced253758157150d43f0 # v7.10.0
with:
commitish: 'main'
header: ${{ env.RELEASE_BODY }}
config-name: github:cpp-linter/.github:/.github/release-drafter.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pull-requests: read
uses: cpp-linter/.github/.github/workflows/release-drafter.yml@main
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add this configuration to your `.pre-commit-config.yaml` file:
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-format
args: [--style=file, --version=21]
Expand All @@ -35,12 +35,16 @@ a `compile_commands.json`, which it looks for in `build/` and a few other direct
it skips clang-tidy on your machine and fails in CI (see
[Compilation database](https://github.com/cpp-linter/cpp-linter-hooks#compilation-database)).

For teams, CI and machines behind a firewall or a company PyPI mirror, also pin the wheel in
`additional_dependencies` so pre-commit installs it once, with the hook (see
[Install the tool with the hook](https://github.com/cpp-linter/cpp-linter-hooks#install-the-tool-with-the-hook)).

## Usage

### Custom clang tool version

> [!TIP]
> The `rev` tag (e.g. `v1.7.0`) is the **project** version, not the clang tool version. Without
> The `rev` tag (e.g. `v1.8.0`) is the **project** version, not the clang tool version. Without
> `--version`, each hook installs the newest clang-format or clang-tidy wheel on PyPI the first time
> it runs and keeps it until pre-commit rebuilds the hook environment, so two machines can run
> different LLVM versions with the same configuration. For production use, always pin the tool
Expand All @@ -53,12 +57,14 @@ it skips clang-tidy on your machine and fails in CI (see
a wheel, the hook fails and lists some of the versions that exist.
- When the hook environment already has a wheel that matches `--version` (or any wheel, without
`--version`), the hook uses it and does not contact pypi.org. Otherwise it looks the version up
on pypi.org and installs it, so that run needs network access.
on pypi.org and installs it, so that run needs network access. pre-commit runs the hook on
groups of files in parallel; one of them installs the wheel and the others wait for it.

### Offline and pre-commit.ci
### Install the tool with the hook

To install the clang tool together with the hook, list the exact wheel in
`additional_dependencies`:
We recommend listing the exact wheel in `additional_dependencies`. pre-commit then installs the
clang tool once, when it creates the hook environment, the same way
[mirrors-clang-format](https://github.com/pre-commit/mirrors-clang-format) does:

```yaml
- id: clang-format
Expand All @@ -69,11 +75,16 @@ To install the clang tool together with the hook, list the exact wheel in
additional_dependencies: [clang-tidy==21.1.6]
```

pre-commit installs `additional_dependencies` when it creates the hook environment (for example
with `pre-commit install-hooks`), so the hooks need no network access when they run. Use this on
[pre-commit.ci](https://pre-commit.ci/), which runs hooks without network access, and behind a
firewall. The pinned wheel must match `--version`; otherwise the hook installs the `--version` one
at run time.
pre-commit installs `additional_dependencies` with the hook (for example on
`pre-commit install-hooks`), through the same package index it uses for the hook itself. The hooks
then never install anything or contact pypi.org when they run, so this works:

- on [pre-commit.ci](https://pre-commit.ci/), which runs hooks without network access,
- behind a firewall or with a company PyPI mirror, where pypi.org may be blocked or slow,
- for teams and CI, where every machine gets exactly the same wheel.

The pinned wheel must match `--version`; otherwise the hook installs the `--version` one at run
time. Without `--version`, the hook uses the pinned wheel.

### clang-format

Expand Down Expand Up @@ -204,7 +215,7 @@ See [Performance optimization](https://github.com/cpp-linter/cpp-linter-hooks#pe
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0 # includes --fix support
rev: v1.8.0 # includes --fix support
hooks:
- id: clang-tidy
args: [--fix]
Expand All @@ -227,7 +238,7 @@ repository root works too.
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-tidy
# Auto-detects ./build/compile_commands.json if present
Expand Down Expand Up @@ -282,7 +293,7 @@ Three self-contained templates plus quick snippets for other common setups.

```yaml
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-format
args: [--style=file, --version=21]
Expand All @@ -297,7 +308,7 @@ or `-j`:

```yaml
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-tidy
args: [--version=21, --jobs=4]
Expand Down Expand Up @@ -334,7 +345,7 @@ This approach ensures that only modified files are checked, further speeding up
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-format
args: [--style=file, --version=21, --verbose] # Shows processed files
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ If you already have a CMake project, you need **two files**:
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-format
args: [--style=file, --version=21]
Expand Down
2 changes: 1 addition & 1 deletion examples/meson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ If you already have a Meson project, configure the hooks and generate a compilat
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.7.0
rev: v1.8.0
hooks:
- id: clang-format
args: [--style=file, --version=21]
Expand Down
Loading