diff --git a/.ci/check-format.sh b/.ci/check-format.sh new file mode 100755 index 0000000..caf16e8 --- /dev/null +++ b/.ci/check-format.sh @@ -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 "") diff --git a/.github/workflows/generate_doc.yaml b/.github/workflows/generate_doc.yaml index a6aec8a..fe640fc 100644 --- a/.github/workflows/generate_doc.yaml +++ b/.github/workflows/generate_doc.yaml @@ -35,3 +35,14 @@ jobs: lkmpg-html.tar.gz tag_name: "latest" 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 diff --git a/.gitignore b/.gitignore index e2ca0bd..650494b 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ lkmpg.pdf *.lg *.idv *.xref + +# format checks +expected-format