Skip to content

Commit d3cd320

Browse files
committed
feat: introduce pre-commit framework
This replaces the custom clang-format script with the pre-commit framework, making it easier to add checks in the future and simplifying GitHub integration. The GH workflow is adapted to run checks now as well. To use it locally, all you need to do is install pre-commit locally, typically via: ``` pip3 install --user pre-commit ``` You can then run `pre-commit run --all` to run it locally. Note that this does _not_ install a Git hook. If you want that as well, run `pre-commit install`. For more details on pre-commit and other installation options, see https://pre-commit.com and https://pre-commit.com/#install
1 parent 5041ca5 commit d3cd320

File tree

3 files changed

+42
-70
lines changed

3 files changed

+42
-70
lines changed

.github/workflows/pre-commit.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Pre-commit checks
2+
3+
on:
4+
# Run workflow for PRs.
5+
pull_request:
6+
7+
# Whenever we have a new commit on main, run the workflow for that.
8+
push:
9+
branches: [main]
10+
11+
jobs:
12+
pre-commit:
13+
name: Pre-commit checks
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{github.event.pull_request.head.sha}}
20+
repository: ${{github.event.pull_request.head.repo.full_name}}
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.10"
25+
- name: Run pre-commit checks on PR
26+
if: github.event_name == 'pull_request'
27+
uses: pre-commit/[email protected]
28+
- name: Run pre-commit checks on main
29+
if: github.event_name != 'pull_request'
30+
uses: pre-commit/[email protected]
31+
with:
32+
extra_args: --all
33+

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exclude: 'test/(catch.hpp|tests-main.cpp)'
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/mirrors-clang-format
5+
rev: v18.1.2
6+
hooks:
7+
- id: clang-format
8+
exclude_types: [json]
9+

bin/check-formatting.sh

-70
This file was deleted.

0 commit comments

Comments
 (0)