Skip to content

Commit c6e58ff

Browse files
committed
Add CI workflow to check example sketches for compliance with the code formatting style
The existing examples_formatter.conf configuration for Artistic Style is used. Although this configuration does add some additional formatting rules, it will most often be possible to achieve compliance simply by using the IDE's Auto Format feature. The repository also contains an examples_formatter.sh script that will automatically format the examples according to the configuration.
1 parent d5ae736 commit c6e58ff

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Diff for: .github/workflows/code-formatting-check.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Code Formatting Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/code-formatting-check.yml"
7+
- "examples/**"
8+
push:
9+
paths:
10+
- ".github/workflows/code-formatting-check.yml"
11+
- "examples/**"
12+
13+
jobs:
14+
check-formatting:
15+
runs-on: ubuntu-latest
16+
17+
env:
18+
# See: https://sourceforge.net/projects/astyle/files/astyle/
19+
ASTYLE_VERSION: 3.1
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
# See: http://astyle.sourceforge.net/
26+
- name: Download Artistic Style
27+
uses: carlosperate/[email protected]
28+
with:
29+
file-url: https://iweb.dl.sourceforge.net/project/astyle/astyle/astyle%20${{ env.ASTYLE_VERSION }}/astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz
30+
location: ${{ runner.temp }}/astyle
31+
32+
# See: http://astyle.sourceforge.net/install.html#_GCC_Makefile
33+
- name: Build Artistic Style
34+
run: |
35+
# Build Artistic Style
36+
cd "${{ runner.temp }}/astyle"
37+
tar --extract --file="astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz"
38+
cd "astyle/build/gcc"
39+
make
40+
41+
# GITHUB_WORKSPACE
42+
- name: Check code formatting
43+
run: |
44+
# Check code formatting of example sketches
45+
# Don't exit on first formatting check fail
46+
set +e
47+
# Set default exit status
48+
EXIT_STATUS=0
49+
while read -r filePath; do
50+
# Check if it's a file (find matches on pruned folders)
51+
if [[ -f "$filePath" ]]; then
52+
if ! diff --strip-trailing-cr "$filePath" <("${{ runner.temp }}/astyle/astyle/build/gcc/bin/astyle" --options="${GITHUB_WORKSPACE}/examples_formatter.conf" --dry-run <"$filePath"); then
53+
echo "ERROR: Non-compliant code formatting in $filePath"
54+
EXIT_STATUS=1
55+
fi
56+
fi
57+
done <<<"$(find "${GITHUB_WORKSPACE}/examples" -regextype posix-extended \( -regex '.*\.((ino)|(h)|(cpp)|(c))$' -and -type f \))"
58+
if [[ "$EXIT_STATUS" != "0" ]]; then
59+
echo "Please do an Auto Format on the sketches:"
60+
echo "Arduino IDE: Tools > Auto Format"
61+
echo "Arduino Web Editor: Ctrl + B"
62+
fi
63+
exit "$EXIT_STATUS"

Diff for: README.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
= Built-in Examples =
22

33
image:https://github.com/arduino/arduino-examples/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Compile+Examples"]
4+
image:https://github.com/arduino/arduino-examples/workflows/Code%20Formatting%20Check/badge.svg["Code Formatting Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Code+Formatting+Check"]
45
image:https://github.com/arduino/arduino-examples/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Spell+Check"]
56

67
These are the example Arduino sketches built in to the Arduino IDE.

0 commit comments

Comments
 (0)