Skip to content

Commit 285c424

Browse files
authored
Add clang-format-diff to github actions (#26445)
Back again with another attempt at #12446 after 6 years. If this proves to be too aggressive/annoying we can dial it back somehow or disable it.
1 parent 22941c8 commit 285c424

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

.clang-format-ignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ignore third_party code from clang-format checks
2+
third_party/*
3+
test/third_party/*
4+
system/lib/libc/musl
5+
system/lib/libcxx
6+
system/lib/libcxxabi
7+
system/lib/libunwind
8+
system/lib/mimalloc
9+
system/lib/llvm-libc

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,18 @@ jobs:
9898
echo "-- This failure is only a warning and can be ignored"
9999
exit 1
100100
fi
101+
102+
clang-format-diff:
103+
env:
104+
LLVM_VERSION: 19
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v4
108+
# Fetch all history for all tags and branches
109+
with:
110+
fetch-depth: 0
111+
- name: Install clang-format
112+
run: |
113+
sudo apt-get install clang-format-19
114+
sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-19 100
115+
- run: tools/maint/clang-format-diff.sh origin/$GITHUB_BASE_REF

tools/maint/clang-format-diff.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Based on binaryen/scripts/clang-format-diff.sh
3+
# TODO(sbc): Switch to pre-packaged github actions once we find one that
4+
# is mature enough for our needs.
5+
6+
set -o errexit
7+
set -o pipefail
8+
set -o xtrace
9+
10+
if [ -n "$1" ]; then
11+
BRANCH="$1"
12+
else
13+
BRANCH="@{upstream}"
14+
fi
15+
16+
MERGE_BASE=$(git merge-base $BRANCH HEAD)
17+
FORMAT_ARGS=${MERGE_BASE}
18+
if [ -n "$LLVM_VERSION" ]; then
19+
FORMAT_ARGS="--binary=clang-format-${LLVM_VERSION} ${FORMAT_ARGS}"
20+
fi
21+
22+
git clang-format ${FORMAT_ARGS} --diff

0 commit comments

Comments
 (0)