Skip to content

Commit

Permalink
Add style checks
Browse files Browse the repository at this point in the history
Add stylecheck in github actions
  • Loading branch information
Jaeyoung-Lim committed Jul 22, 2021
1 parent 2ff71a7 commit 95de616
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 297 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/check_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Style Checks

on:
push:
branches:
- master
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container:
- 'px4io/px4-dev-simulation-focal:2020-09-14'
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v1
- name: submodule update
run: git submodule update --init --recursive
- name: Install clang-format
run: apt update && apt install -y clang-format-6.0
- name: Check Code format
working-directory: Tools
run: |
./check_code_format.sh ..
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ docker-run:
estimate-model:
python3 Tools/parametric_model/generate_parametric_model.py --model ${model} --config ${config} --data_selection ${data_selection} ${log}

format:
Tools/fix_code_style.sh .
10 changes: 10 additions & 0 deletions Tools/check_code_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Fix style recursively in all the repository
sh fix_code_style.sh ..

# Print the diff with the remote branch (empty if no diff)
git --no-pager diff -U0 --color

# Check if there are changes, and failed
if ! git diff-index --quiet HEAD --; then echo "Code style check failed, please run clang-format (e.g. with scripts/fix_code_style.sh)"; exit 1; fi
21 changes: 21 additions & 0 deletions Tools/fix_code_style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

STYLE="google"

if [ "$#" -eq 0 ]; then
echo "Usage: $0 <src_file | dir>"
echo ""
echo "ERROR: At least one source file or one directory must be provided!"

exit 1
fi

for arg in "$@"
do
if [ -f $arg ]; then
clang-format-6.0 -i -style='{BasedOnStyle: google, ColumnLimit: 120}' $arg
elif [ -d $arg ]; then
find $arg -iname '*.h' -o -iname '*.cpp' -o -iname '*.hpp' | xargs clang-format-6.0 -i -style='{BasedOnStyle: google, ColumnLimit: 120}'
find $arg -iname '*.h' -o -iname '*.cpp' -o -iname '*.hpp' | xargs chmod 644
fi
done
Loading

0 comments on commit 95de616

Please sign in to comment.