Skip to content

Commit

Permalink
Make the CI check for bad formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jul 7, 2021
1 parent b9079f6 commit 5f89c09
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ jobs:
python3 -m pip install -U flake8
python3 -m flake8 --exclude=thirdParty .
clang-format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
sudo apt install -y clang-format
.github/workflows/source/clang-format
static-analysis:
runs-on: ubuntu-20.04
steps:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/source/clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Copyright 2016-2021 Axel Huebl
#
# License: LGPLv3+

# search recursive inside a folder if a file contains tabs
#
# @result 0 if no files are found, else 1
#

__awkscript() {
cat << EOF
BEGIN {
modified = 0;
}
{
if (\$1 == "M") {
modified = 1;
}
}
END {
print modified;
}
EOF
}
awkscript="$(__awkscript)"

./format.sh
if [[ $? -ne 0 ]]
then
echo "# Unable to format the source tree"
exit 1
fi

modified="$(git status --short | awk "$awkscript")"
if [[ "$modified" -eq 1 ]]
then
cat << EOF
# Code must be formatted by clang-format.
# Use the format.sh script contained in the source tree.
# Bad files:
EOF
git status --short \
| awk '{if ($1 == "M"){ printf "# %s\n", $2 }}'
exit 1
fi

exit 0

0 comments on commit 5f89c09

Please sign in to comment.