File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ name : clang-format
2+
3+ on :
4+ pull_request :
5+ paths :
6+ - ' **.h'
7+ - ' **.cc'
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-latest
16+ steps :
17+ - name : Checkout PR branch
18+ uses : actions/checkout@v4
19+ with :
20+ ref : ${{ github.event.pull_request.head.sha }}
21+ fetch-depth : 0
22+
23+ - name : Setup Python
24+ uses : actions/setup-python@v5
25+ with :
26+ python-version : " 3.11"
27+
28+ - name : Install clang-format
29+ run : |
30+ curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
31+ os_codename="`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`"
32+ echo "deb https://apt.llvm.org/${os_codename}/ llvm-toolchain-${os_codename}-18 main" | sudo tee -a /etc/apt/sources.list
33+ sudo apt update
34+ sudo apt install -y clang-format-18
35+
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-18 --diff --binary clang-format-18 --commit $PR_BASE -- src/ || \
45+ (echo "Please run the following git-clang-format locally to fix the formatting: \n
46+ git-clang-format HEAD~\n
47+ for multiple commits we should place the formatting changes in the related commit with:\n
48+ \t\tgit rebase -i -x \"git-clang-format-18 main && git commit -a --allow-empty --fixup=HEAD\" --strategy-option=theirs origin/main\n
49+ \t\t Then inspect the results with: git log --oneline\n
50+ \t\t Then squash without poluting the history with: git rebase --autosquash -i main\n" && exit 1)
You can’t perform that action at this time.
0 commit comments