Skip to content

Commit

Permalink
github/actions/static: clean up clang-format checker
Browse files Browse the repository at this point in the history
This is to be squahed before push

Signed-off-by: MyungJoo Ham <[email protected]>
  • Loading branch information
myungjoo committed Jan 15, 2024
1 parent 3e046a2 commit 6b31660
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions .github/workflows/static.check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,37 @@ jobs:
runs-on: ubuntu-latest
name: Static checks
steps:
- uses: actions/checkout@v4
- name: Preparing step 1...
uses: actions/checkout@v4
with:
fetch-depth: 5
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
since_last_remote_commit: true
- name: List all files changed
fetch-depth: 0
- name: Preparing step 2... Saving to files
shell: bash
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
BEFORE_REF: ${{ github.event.before }}
AFTER_REF: ${{ github.event.after }}
REFS: ${{ github.event.pull_request.commits }}
run: |
for file in "$ALL_CHANGED_FILES"; do
if [ -z $REF ]; then REF=1; fi
git show --pretty="format:" --name-only --diff-filter=AMRC -${REF} | sort | uniq | grep '.' > changed.files
for file in `cat changed.files`; do
echo "$file was changed"
done
- name: Run clang-format for cc/hh/hpp/cpp files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- name: /Checker/ clang-format for .cc/.hh/.hpp/.cpp files
shell: bash
env:
BEFORE_REF: ${{ github.event.before }}
AFTER_REF: ${{ github.event.after }}
REFS: ${{ github.event.pull_request.commits }}
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"
echo "::error .clang-format file not found"
exit 1
fi
for file in "$ALL_CHANGED_FILES"; do
for file in `cat 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}
Expand All @@ -47,7 +51,7 @@ jobs:
git diff -- *.cc *.hh *.hpp *.cpp > .ci.clang-format.patch
SIZE=$(stat -c%s .ci.clang-format.patch)
if [[ $SIZE -ne 0 ]]; then
echo "clang-format shows that the commit has style errors."
echo "::error clang-format has found style errors in C++ files."
cat .ci.clang-format.patch
exit 1
fi
Expand Down

0 comments on commit 6b31660

Please sign in to comment.