|
4 | 4 | pull_request:
|
5 | 5 | paths:
|
6 | 6 | - ".github/workflows/code-formatting-check.yml"
|
| 7 | + - "examples_formatter.sh" |
7 | 8 | - "examples/**"
|
8 | 9 | push:
|
9 | 10 | paths:
|
10 | 11 | - ".github/workflows/code-formatting-check.yml"
|
| 12 | + - "examples_formatter.sh" |
11 | 13 | - "examples/**"
|
12 | 14 |
|
13 | 15 | jobs:
|
@@ -37,27 +39,18 @@ jobs:
|
37 | 39 | tar --extract --file="astyle_${{ env.ASTYLE_VERSION }}_linux.tar.gz"
|
38 | 40 | cd "astyle/build/gcc"
|
39 | 41 | make
|
| 42 | + # Add installation to PATH: |
| 43 | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path |
| 44 | + echo "${{ runner.temp }}/astyle/astyle/build/gcc/bin" >> "$GITHUB_PATH" |
40 | 45 |
|
41 |
| - # GITHUB_WORKSPACE |
42 |
| - - name: Check code formatting |
| 46 | + - name: Format examples |
| 47 | + run: ./examples_formatter.sh |
| 48 | + |
| 49 | + - name: Check formatting |
43 | 50 | 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 |
| 51 | + if ! git diff --color --exit-code; then |
59 | 52 | echo "Please do an Auto Format on the sketches:"
|
60 | 53 | echo "Arduino IDE: Tools > Auto Format"
|
61 | 54 | echo "Arduino Web Editor: Ctrl + B"
|
| 55 | + exit 1 |
62 | 56 | fi
|
63 |
| - exit "$EXIT_STATUS" |
0 commit comments