Skip to content

Commit b137f9c

Browse files
hzellerlromor
authored andcommitted
Make run-clang-format.sh work well in before-submit and CI
In scripts/before-submit.sh, we do not want to get an error when anything is formatted, we just want it to be done. In the CI, however, we want to use the same script and have it fail if not.
1 parent 7a97bc8 commit b137f9c

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,8 @@ jobs:
6767
- name: Run formatting style check
6868
run: |
6969
clang-format-18 --version
70-
CLANG_FORMAT=clang-format-18 scripts/run-clang-format.sh
71-
git diff > /tmp/format-diff
72-
if [ -s "/tmp/format-diff" ]; then
73-
echo "Difference to optimal formatting"
74-
cat /tmp/format-diff
75-
echo
76-
echo "=================== To Fix ==========================="
77-
echo "Run scripts/run-format.sh"
78-
echo "then"
79-
echo " git commit -a --amend"
80-
echo " git push -f"
81-
exit 1
82-
fi
70+
RUNNING_IN_CI=1 CLANG_FORMAT=clang-format-18 \
71+
scripts/run-clang-format.sh
8372
8473
ClangTidy:
8574
runs-on: ubuntu-24.04
@@ -117,4 +106,3 @@ jobs:
117106
clang-tidy-18 --version
118107
CLANG_TIDY=clang-tidy-18 scripts/run-clang-tidy-cached.cc \
119108
|| ( cat fpga-assembler_clang-tidy.out ; exit 1)
120-

scripts/run-clang-format.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FORMAT_OUT=${TMPDIR:-/tmp}/clang-format-diff.out
66

77
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
88
BUILDIFIER=${BUILDIFIER:-buildifier}
9+
RUNNING_IN_CI=${RUNNING_IN_CI:-0}
910

1011
${CLANG_FORMAT} --version
1112

@@ -19,17 +20,21 @@ if command -v ${BUILDIFIER} >/dev/null; then
1920
${BUILDIFIER} -lint=fix MODULE.bazel $(find . -name BUILD -o -name "*.bzl")
2021
fi
2122

22-
# Check if we got any diff
23-
git diff > ${FORMAT_OUT}
24-
25-
if [ -s ${FORMAT_OUT} ]; then
26-
echo "Style not matching"
27-
echo "Run"
28-
echo " .github/bin/run-clang-format.sh"
29-
echo "-------------------------------------------------"
30-
echo
31-
cat ${FORMAT_OUT}
32-
exit 1
23+
# If in CI, we want to report changes, as we don't expect them
24+
if [ "$RUNNING_IN_CI" -eq 1 ]; then
25+
# Check if we got any diff
26+
git diff > ${FORMAT_OUT}
27+
28+
if [ -s ${FORMAT_OUT} ]; then
29+
echo "Style not matching"
30+
echo "Run"
31+
echo " scripts/run-clang-format.sh"
32+
echo "and amend PR."
33+
echo "-------------------------------------------------"
34+
echo
35+
cat ${FORMAT_OUT}
36+
exit 1
37+
fi
3338
fi
3439

3540
exit 0

0 commit comments

Comments
 (0)