Skip to content

Commit

Permalink
ci: lint cpp source
Browse files Browse the repository at this point in the history
  • Loading branch information
sethfischer committed Jun 11, 2021
1 parent 14894ee commit b46a965
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: lint

on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Lint Cpp source
run: |
sudo apt-get -y install clang-format
bash lint-c.sh
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Beginning Arduino with PlatformIO
=================================

|docs-status| |build-status|
|docs-status| |build-status| |lint-status|


Beginner's Arduino projects for the `PlatformIO`_ IDE.
Expand Down Expand Up @@ -37,3 +37,6 @@ License
.. |build-status| image:: https://github.com/sethfischer/arduino-beginner/actions/workflows/build.yml/badge.svg
:target: https://github.com/sethfischer/arduino-beginner/actions/workflows/build.yml
:alt: Build status
.. |lint-status| image:: https://github.com/sethfischer/arduino-pio/actions/workflows/lint.yml/badge.svg
:target: https://github.com/sethfischer/arduino-pio/actions/workflows/lint.yml
:alt: Lint status
22 changes: 22 additions & 0 deletions lint-c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

shopt -s globstar

exit_code=0

# Check clang-format
for filename in **/*.{cpp,h} ; do
if [ -f "$filename" ]; then
echo -e "Check formatting of ${filename}"
diff "$filename" <(clang-format -assume-filename=main.cpp "$filename") 1>&2
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
exit_code=1
echo -e "Fail"
else
echo -e "Pass"
fi
fi
done

exit $exit_code

0 comments on commit b46a965

Please sign in to comment.