Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add style checks #114

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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