Check coding style in CI

This commit is contained in:
Jim Huang 2021-08-17 13:07:06 +08:00
parent 48cb100473
commit 2db805da2c
3 changed files with 35 additions and 0 deletions

21
.ci/check-format.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(cpp|cc|c|h)\$")
CLANG_FORMAT=$(which clang-format-11)
if [ $? -ne 0 ]; then
CLANG_FORMAT=$(which clang-format)
if [ $? -ne 0 ]; then
echo "[!] clang-format not installed. Unable to check source file format policy." >&2
exit 1
fi
fi
set -x
for file in ${SOURCES};
do
$CLANG_FORMAT ${file} > expected-format
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
done
exit $($CLANG_FORMAT --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")

View File

@ -35,3 +35,14 @@ jobs:
lkmpg-html.tar.gz lkmpg-html.tar.gz
tag_name: "latest" tag_name: "latest"
prerelease: true prerelease: true
coding_style:
runs-on: ubuntu-20.04
steps:
- name: checkout code
uses: actions/checkout@v2
- name: style check
run: |
sudo apt-get install -q -y clang-format-11
sh .ci/check-format.sh
shell: bash

3
.gitignore vendored
View File

@ -29,3 +29,6 @@ lkmpg.pdf
*.lg *.lg
*.idv *.idv
*.xref *.xref
# format checks
expected-format