File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed
Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -euo pipefail
4+
5+ RANGE=" "
6+
7+ while [[ $# -gt 0 ]]; do
8+ echo $1
9+ echo $2
10+ case " $1 " in
11+ --range)
12+ RANGE=" $2 "
13+ shift 2
14+ ;;
15+ * )
16+ echo " Unknown arg $1 " >&2
17+ exit 64
18+ ;;
19+ esac
20+ done
21+
22+ regex=' \.(c|cc|cpp|cxx|h|hh|hpp|hxx)$'
23+
24+ if [[ -n $RANGE ]]; then
25+ files=$( git diff --name-only " $RANGE " | grep -E " $regex " || true)
26+ else
27+ files=$( git diff --cached --name-only --diff-filter=ACMR | grep -E " $regex " || true)
28+ fi
29+ echo " Checking $files "
30+ [[ -z $files ]] && exit 0
31+
32+ clang_bin=" ${CLANG_FORMAT:- clang-format} "
33+ if ! command -v " $clang_bin " > /dev/null 2>&1 ; then
34+ if [[ -x " /c/Program Files/LLVM/bin/clang-format.exe" ]]; then
35+ clang_bin=" /c/Program Files/LLVM/bin/clang-format.exe"
36+ fi
37+ fi
38+
39+ " $clang_bin " -style=file --dry-run -fallback-style=none -n -Werror $files
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ exec " $( git rev-parse --show-toplevel) /.github/hooks/clang-format-check.sh"
Original file line number Diff line number Diff line change 1+ name : Clang format check
2+
3+ on :
4+ push :
5+
6+ jobs :
7+ format :
8+ runs-on : ubuntu-latest
9+ steps :
10+ - uses : actions/checkout@v4
11+ with :
12+ fetch-depth : 0
13+
14+ - name : Install clang-format
15+ run : |
16+ sudo apt update && sudo apt install -y clang-format
17+
18+ - name : Run clang-format-check
19+ id : clang-format
20+ run : |
21+ chmod +x .github/hooks/clang-format-check.sh
22+ ./.github/hooks/clang-format-check.sh --range "${{ github.event.before }}..${{ github.sha }}"
You can’t perform that action at this time.
0 commit comments