diff --git a/.ci/check-format.sh b/.ci/check-format.sh new file mode 100755 index 0000000..3f955cc --- /dev/null +++ b/.ci/check-format.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e -u -o pipefail + +SOURCES=$(find $(git rev-parse --show-toplevel) | egrep "\.(c|cxx|cpp|h|hpp)\$") + +set -x + +for file in ${SOURCES}; +do + clang-format-18 ${file} > expected-format + diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format +done +exit $(clang-format-18 --output-replacements-xml ${SOURCES} | egrep -c "") \ No newline at end of file diff --git a/.ci/check-newline.sh b/.ci/check-newline.sh new file mode 100755 index 0000000..b1cb69d --- /dev/null +++ b/.ci/check-newline.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -e -u -o pipefail + +ret=0 +show=0 +# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e +while IFS= read -rd '' f; do + if file --mime-encoding "$f" | grep -qv binary; then + tail -c1 < "$f" | read -r _ || show=1 + if [ $show -eq 1 ]; then + echo "Warning: No newline at end of file $f" + ret=1 + show=0 + fi + fi +done < <(git ls-files -z src tests/arch-test-target) + +exit $ret \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5bc9959 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,16 @@ +name: CI + +on: [push, pull_request] + +jobs: + coding-style: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: coding convention + run: | + sudo apt-get update + sudo apt-get install -q -y clang-format-18 + .ci/check-newline.sh + .ci/check-format.sh + shell: bash \ No newline at end of file