diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-06 18:27:54 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-06-06 23:09:58 (GMT) |
| commit | 7c45f185a32c7bcff47c8fda1acdec82d3213717 (patch) | |
| tree | 53b0419fe2a19e6ec5c89d0be0a11dcd8d4ceb00 /tests/test-format.sh | |
| parent | 94b1b330fc1f6e941a797fedabade4e790e28bc2 (diff) | |
| parent | 35dcf8c8607483c104711c9398d47d57147f4389 (diff) | |
Merge remote-tracking branch 'origin/develop' into analog24
Diffstat (limited to 'tests/test-format.sh')
| -rwxr-xr-x | tests/test-format.sh | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test-format.sh b/tests/test-format.sh new file mode 100755 index 0000000..86667c7 --- /dev/null +++ b/tests/test-format.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -e + +if [ -z "$GITHUB_BASE_REF" ] +then + echo "This script is only meant to be run in a GitHub Workflow" + exit 1 +fi + +CHANGED_FILES=$(git diff --name-only "$GITHUB_BASE_REF"...HEAD) + +CHANGED=0 + +for file in $CHANGED_FILES +do + [ -e "$file" ] || continue + case "$file" in + src/libs/*) continue ;; + *.cpp|*.h) + echo Checking "$file" + clang-format -i "$file" + if ! git diff --quiet + then + printf "\033[31mError:\033[0m Formatting error in %s\n" "$file" + CHANGED=1 + git add "$file" + git commit -q -m "Apply clang-format to $(basename "$file")" + printf "Creating patch " + git format-patch HEAD~ + fi + esac +done + +if [ $CHANGED = 1 ] +then + printf "\033[31mError:\033[0m Issues found. You may use the patches provided as artifacts to format the code." + exit 1 +fi + +exit 0 |
