Skip to content

Commit d57e45a

Browse files
committed
CI: Add formatting validation steps
The following scripts are added to GitHub Actions workflow: - check-format.sh to validate C/C++ and shell script formatting - check-newline.sh to ensure files end with newline Close #33
1 parent 36e82af commit d57e45a

File tree

8 files changed

+654
-594
lines changed

8 files changed

+654
-594
lines changed

.ci/check-format.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -u -o pipefail
4+
5+
ret=0
6+
7+
# Check C/C++ files with clang-format
8+
while IFS= read -r -d '' file; do
9+
clang-format-18 -n --Werror "${file}" || ret=1
10+
done < <(git ls-files -z '*.c' '*.cpp' '*.h' ':!:*/submodule/*')
11+
12+
# Check shell scripts with shfmt
13+
while IFS= read -r file; do
14+
diff <(cat "${file}") <(shfmt -i 4 -bn -ci -sr "${file}")
15+
if [ $? -ne 0 ]; then
16+
echo "${file}" "mismatch"
17+
ret=1
18+
fi
19+
done < <(git ls-files '*.sh')
20+
21+
exit ${ret}

.ci/check-newline.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -u -o pipefail
4+
5+
ret=0
6+
show=0
7+
# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
8+
while IFS= read -rd '' f; do
9+
if file --mime-encoding "$f" | grep -qv binary; then
10+
tail -c1 < "$f" | read -r _ || show=1
11+
if [ $show -eq 1 ]; then
12+
echo "Warning: No newline at end of file $f"
13+
ret=1
14+
show=0
15+
fi
16+
fi
17+
done < <(git ls-files -z app kernel lib arch include)
18+
19+
exit $ret

0 commit comments

Comments
 (0)