Skip to content

Commit 655abeb

Browse files
vaithakvgvassilev
authored andcommitted
Run git-clang-format on PR only
1 parent b1cdd91 commit 655abeb

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,6 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
jobs:
17-
precheckin:
18-
runs-on: ubuntu-22.04
19-
steps:
20-
- name: Checkout PR branch
21-
uses: actions/checkout@v3
22-
with:
23-
ref: ${{ github.event.pull_request.head.sha }}
24-
fetch-depth: 0
25-
- name: Setup Python
26-
uses: actions/setup-python@v4
27-
with:
28-
python-version: 3.7
29-
- name: Install clang-format
30-
run: |
31-
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
32-
echo "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" | sudo tee -a /etc/apt/sources.list
33-
sudo apt update
34-
sudo apt install -y clang-format-15
35-
- name: Download git-clang-format
36-
run: |
37-
wget https://raw.githubusercontent.com/llvm/llvm-project/main/clang/tools/clang-format/git-clang-format
38-
chmod +x git-clang-format
39-
- name: Run git-clang-format
40-
run: |
41-
PR_BASE=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
42-
echo "running git clang-format against $PR_BASE commit"
43-
git \
44-
-c color.ui=always \
45-
-c diff.wsErrorHighlight=all \
46-
-c color.diff.whitespace='red reverse' \
47-
clang-format-15 --diff --binary clang-format-15 --commit $PR_BASE -- include/ lib/ || \
48-
(echo "Please run the following git-clang-format locally to fix the formatting: \n
49-
git clang-format origin/main -- include/ lib/" && exit 1)
5017
build:
5118
name: ${{ matrix.name }}
5219
runs-on: ${{ matrix.os }}

.github/workflows/clang-format.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: clang-format
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.h'
7+
- '**.cpp'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
precheckin:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- name: Checkout PR branch
18+
uses: actions/checkout@v3
19+
with:
20+
ref: ${{ github.event.pull_request.head.sha }}
21+
fetch-depth: 0
22+
- name: Setup Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: 3.7
26+
- name: Install clang-format
27+
run: |
28+
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
29+
echo "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main" | sudo tee -a /etc/apt/sources.list
30+
sudo apt update
31+
sudo apt install -y clang-format-15
32+
- name: Download git-clang-format
33+
run: |
34+
wget https://raw.githubusercontent.com/llvm/llvm-project/main/clang/tools/clang-format/git-clang-format
35+
chmod +x git-clang-format
36+
- name: Run git-clang-format
37+
run: |
38+
PR_BASE=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
39+
echo "running git clang-format against $PR_BASE commit"
40+
git \
41+
-c color.ui=always \
42+
-c diff.wsErrorHighlight=all \
43+
-c color.diff.whitespace='red reverse' \
44+
clang-format-15 --diff --binary clang-format-15 --commit $PR_BASE -- include/ lib/ || \
45+
(echo "Please run the following git-clang-format locally to fix the formatting: \n
46+
git clang-format origin/main -- include/ lib/" && exit 1)

0 commit comments

Comments
 (0)