-
-
Notifications
You must be signed in to change notification settings - Fork 94
85 lines (76 loc) · 3.12 KB
/
clang-format.yml
File metadata and controls
85 lines (76 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Clang-Format Check
# This workflow verifies that all tracked C/C++ files in the repository
# are formatted according to the .clang-format rules.
#
# It uses:
# - clang-format (installed via apt)
# - a Go-based helper (cmd/clang-filter) via `go run`
# - the shell script `./scripts/_format_c_code.sh` to orchestrate everything
#
# The workflow runs:
# - on every push to any branch
# - on every pull request
on:
push:
branches:
- "**"
pull_request:
jobs:
clang-format-check:
runs-on: ubuntu-latest
steps:
#########################################################################
# 1) Check out the repository so we have access to:
# - source files
# - .clang-format
# - .clang-format-ignore
# - cmd/clang-filter
# - scripts/_format_c_code.sh
#########################################################################
- name: Check out repository
uses: actions/checkout@v6
with:
# Full git history is not strictly required for formatting,
# but some tools or future changes might rely on it.
fetch-depth: 0
#########################################################################
# 2) Install clang-format on the runner.
#
# We rely on Ubuntu's clang-format package. If you require a specific
# version, you can pin it here or use a prebuilt toolchain image.
#########################################################################
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format
- name: Show clang-format version
run: clang-format --version
#########################################################################
# 3) Set up Go toolchain for `go run ./cmd/clang-filter`
#
# The Go helper uses github.com/sabhiram/go-gitignore to implement
# gitignore-style rules for .clang-format-ignore.
#########################################################################
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: false
# Optional but recommended: download all Go module dependencies up front.
# This avoids doing network fetches during `go run` and can speed up CI.
- name: Download Go modules
run: go mod download
#########################################################################
# 4) Run clang-format in CHECK mode via the shell script.
#
# The script:
# - collects tracked C/C++ files (git ls-files)
# - filters them via `go run ./cmd/clang-filter` using .clang-format-ignore
# - runs clang-format in CHECK mode (no in-place changes)
# - prints per-file errors using GitHub Actions "::error" annotations
# - fails the job (exit 1) if any file is misformatted
#########################################################################
- name: Run clang-format in check mode
run: |
chmod +x ./scripts/_format_c_code.sh
./scripts/_format_c_code.sh check