File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # ignore third_party code from clang-format checks
2+ third_party/*
3+ test/third_party/*
Original file line number Diff line number Diff line change 1+ name : clang-format-diff
2+ 
3+ on : [pull_request]
4+
5+ jobs :
6+ clang_format_diff :
7+ runs-on : ubuntu-latest
8+ steps :
9+ - uses : actions/checkout@v4
10+ # Fetch all history for all tags and branches
11+ with :
12+ fetch-depth : 0
13+ - name : Install clang-format
14+ run : |
15+ sudo apt-get install clang-format-19
16+ sudo update-alternatives --install /usr/bin/git-clang-format git-clang-format /usr/bin/git-clang-format-19 100
17+ - run : tests/clang-format-diff.sh origin/$GITHUB_BASE_REF
Original file line number Diff line number Diff line change 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+
9+ if [ -n " $1 " ]; then
10+ BRANCH=" $1 "
11+ elif [ -n " $GITHUB_BASE_REF " ]; then
12+ BRANCH=" origin/$GITHUB_BASE_REF "
13+ else
14+ BRANCH=" @{upstream}"
15+ fi
16+
17+ MERGE_BASE=$( git merge-base $BRANCH HEAD)
18+ FORMAT_ARGS=${MERGE_BASE}
19+ if [ -n " $LLVM_VERSION " ]; then
20+ FORMAT_ARGS=" --binary=clang-format-${LLVM_VERSION} ${FORMAT_MSG} "
21+ fi
22+
23+ FORMAT_MSG=$( git clang-format ${FORMAT_ARGS} -q --diff || true)
24+ if [ -n " $FORMAT_MSG " -a " $FORMAT_MSG " != " no modified files to format" ]
25+ then
26+ echo " Please run git clang-format with clang-format-${LLVM_VERSION} before committing, or apply this diff:"
27+ echo
28+ # Run git clang-format again, this time without capruting stdout. This way
29+ # clang-format format the message nicely and add color.
30+ git clang-format ${FORMAT_ARGS} -q --diff
31+ exit 1
32+ fi
You can’t perform that action at this time.
0 commit comments