Skip to content

Commit 4f6cd6d

Browse files
committed
Add clang-format-diff to github actions
Back again with another attempt at #12446 after 6 years.
1 parent df2e576 commit 4f6cd6d

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

.clang-format-ignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ignore third_party code from clang-format checks
2+
third_party/*
3+
test/third_party/*

.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

system/include/emscripten/emscripten.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void emscripten_run_script(const char * _Nonnull script);
4343
int emscripten_run_script_int(const char * _Nonnull script);
4444
char *emscripten_run_script_string(const char * _Nonnull script);
4545
void emscripten_async_run_script(const char * _Nonnull script, int millis);
46-
void emscripten_async_load_script(const char * _Nonnull script, em_callback_func onload, em_callback_func onerror);
46+
void emscripten_async_load_script(const char* _Nonnull script, em_callback_func onload, em_callback_func onerror);
4747

4848
void emscripten_set_main_loop(em_callback_func func, int fps, bool simulate_infinite_loop);
4949

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)