Skip to content

github/actions/static: clean up clang-format checker #17

github/actions/static: clean up clang-format checker

github/actions/static: clean up clang-format checker #17

Workflow file for this run

name: Static checkers and verifiers
on:
pull_request:
branches: [ main ]
push:
jobs:
simple_script_checkers:
runs-on: ubuntu-latest
name: Static checks
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: /Preparing/ list changed files.
env:
BEFORE_REF: ${{ github.event.before }}
AFTER_REF: ${{ github.event.after }}
run: |
git show --pretty="format:" --name-only --diff-filter=AMRC "$BEFORE_REF...$AFTER_RET" | sort | uniq | grep '.' > changed.files
for file in `cat changed.files` : do
echo "$file was changed"
done
- name: /Checker/ clang-format for .cc/.hh/.hpp/.cpp files
shell: bash
run: |
sudo apt update && sudo apt-get install clang-format
echo "Check .clang-format file"
if [ ! -f ".clang-format" ]; then
echo ".clang-format file not found"
exit 1
fi
for file in `cat /tmp/changed.files` do
if [[ "$file" =~ .*\.hh$ ]] || [[ "$file" =~ .*\.hpp ]] || [[ "$file" =~ .*\.cc$ ]] || [[ "$file" =~ .*\.cpp ]]; then
echo "$file appears to be a C++ file. Applying clang-format"
clang-format -i ${file}
else
echo "$file appears not to be C++ file. skipping clang-format"
fi
done
git diff -- *.cc *.hh *.hpp *.cpp > .ci.clang-format.patch
SIZE=$(stat -c%s .ci.clang-format.patch)
if [[ $SIZE -ne 0 ]]; then
echo "::error clang-format has found style errors in C++ files."
cat .ci.clang-format.patch
exit 1
fi
echo "clang-format shows no style errors."