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