Skip to content

Commit ba9fa7e

Browse files
committed
Actions (clang-format): Enforce clang-format clean C/C++ code
1 parent 35d215c commit ba9fa7e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.github/workflows/clang-format.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Enforce clang-format
2+
3+
on:
4+
pull_request:
5+
push:
6+
schedule:
7+
- cron: '0 3 * * 5' # Every Friday at 3am
8+
9+
jobs:
10+
clang-format:
11+
name: Enforce clang-format
12+
runs-on: ubuntu-22.04
13+
env:
14+
CLANG_MAJOR_VERSION: 16
15+
steps:
16+
17+
- uses: actions/checkout@v3
18+
19+
- name: Add Clang/LLVM repositories
20+
run: |-
21+
set -x
22+
source /etc/os-release
23+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
24+
sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-${CLANG_MAJOR_VERSION} main"
25+
26+
- name: Install clang-format
27+
run: |-
28+
set -x
29+
sudo apt-get update
30+
sudo apt-get install --yes --no-install-recommends -V \
31+
clang-format-${CLANG_MAJOR_VERSION}
32+
33+
- name: Enforce clang-format
34+
run: |-
35+
set -x -o pipefail
36+
clang-format-${CLANG_MAJOR_VERSION} --version
37+
git ls-files \*.{c,cpp,h,hpp} \
38+
|xargs clang-format-${CLANG_MAJOR_VERSION} --style=file -i
39+
git diff --exit-code # i.e. reject non-empty diff

0 commit comments

Comments
 (0)