From d9f2df58ee661ae979f46709b87749e6a086f3da Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 29 Mar 2021 15:29:31 -0400 Subject: [PATCH] chore: Format on CI --- .github/workflows/main.yaml | 12 ++++++++++++ format.sh | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..3076dbf --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,12 @@ +# CI workflow +name: sledge +on: [push, pull_request] + +# job control +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Clang Format + run: ./format.sh -d diff --git a/format.sh b/format.sh index 8c6a804..b901144 100755 --- a/format.sh +++ b/format.sh @@ -25,9 +25,34 @@ if ((major < required_major)) || ((minor < required_minor)) || ((patch < require exit 1 fi -# Match all *.c and *.h files in ./runtime -# Excluding those in the jsmn or http-parser submodules -# And format them with clang-format -find ./runtime -type f -path "./*.[ch]" | - grep --invert-match -E "./runtime/thirdparty/*|./runtime/tests/gocr/*|./runtime/tests/TinyEKF/*|./runtime/tests/CMSIS_5_NN/*|./runtime/tests/sod/*|**/thirdparty/*" | - xargs clang-format -i +help() { + echo "Usage: $0 [OPTION]..." + echo "Formats source code in the repository, applying formatting in place by default" + echo "" + echo "-h, --help Print Help" + echo "-d, --dry-run Dry run formatters, returning 0 when code passes, 1 otherwise" + echo "" + echo "Exit status:" + echo "0 if code required no formatting" + echo "non-zero exit status otherwise" +} + +dry_run() { + find runtime \ + \( -path "runtime/thirdparty" -o -path "runtime/tests/gocr" -o -path "runtime/tests/TinyEKF" -o -path "runtime/tests/CMSIS_5_NN" -o -path "runtime/tests/sod" -o -path "runtime/tests/**/thirdparty" \) -prune -false -o \ + -type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print | + xargs clang-format -Werror -n -ferror-limit=0 +} + +format() { + find runtime \ + \( -path "runtime/thirdparty" -o -path "runtime/tests/gocr" -o -path "runtime/tests/TinyEKF" -o -path "runtime/tests/CMSIS_5_NN" -o -path "runtime/tests/sod" -o -path "runtime/tests/**/thirdparty" \) -prune -false -o \ + -type f \( -iname \*.h -o -iname \*.c -o -iname \*.s \) -print | + xargs clang-format -i +} + +case $1 in + "-h" | "--help") help ;; + "-d" | "--dry-run") dry_run ;; + "") format ;; +esac