Skip to content

Commit

Permalink
Add code format check as GitHub workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
karnkaul committed Feb 2, 2024
1 parent d975f25 commit b91e3fd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/format_check_diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

[[ ! $(git --version) ]] && exit 1

output=$(git diff)

if [[ "$output" != "" ]]; then
echo "One or more source files are not formatted!"
exit 1
fi

echo "All source files are formatted"
exit
11 changes: 11 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: format-check
on: [push]
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: format code
run: ./tools/format_code.sh
- name: check diff
run: ./.github/format_check_diff.sh
22 changes: 22 additions & 0 deletions tools/format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

[[ ! $(clang-format --version) ]] && exit 1

script_path=${0%/*}
project_root=${script_path%/*}

if [[ "$0" != "$project_root" ]] && [[ "$project_root" != "" ]]; then
cd "$project_root" || exit 1
echo "-- Changed pwd to $(pwd)"
fi

files=$(find DogTales -name "*.?pp")
if [[ "$files" == "" ]]; then
echo "-- No source files found"
exit
fi

clang-format -i $files
echo -e "-- Formatted Files:\n$files\n"

exit

0 comments on commit b91e3fd

Please sign in to comment.