Skip to content

Commit 44112c3

Browse files
author
Soren Ptak
committed
Update the uncrustify formatting action to use fd and smaller test cases. Add a README in, and add in the gitattribute file so the line endings don't get changed
1 parent 1a16cea commit 44112c3

34 files changed

+2243
-19311
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
formatting/filesWithCRLFEndings/* eol=crlf
2+
clang-formatting/filesWithFormattingErrors/* eol=crlf

.github/workflows/formattingTests.yml

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
name: Formatting Tests
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: [main,v2]
8+
workflow_dispatch:
9+
10+
env:
11+
# The bash escape character is \033
12+
bashPass: \033[32;1mPASSED -
13+
bashInfo: \033[33;1mINFO -
14+
bashFail: \033[31;1mFAILED -
15+
bashEnd: \033[0m
16+
17+
jobs:
18+
uncrustify-formatting-success-cases:
19+
runs-on: ubuntu-20.04
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- env:
24+
stepName: "Functional | Success | Exclude Files and Dirs"
25+
name: ${{ env.stepName }}
26+
id: exclude-dirs-with-errors
27+
uses: ./formatting
28+
with:
29+
path: formatting/goodFiles
30+
exclude-dirs: "fileWithErrorInclude, fileWithErrorSource"
31+
exclude-files: "formatErrorTest.h, formatErrorTest.c"
32+
33+
- env:
34+
stepName: "Functional | Success | Exclude Just Files"
35+
name: ${{ env.stepName }}
36+
id: exclude-files-with-errors
37+
uses: ./formatting
38+
with:
39+
path: formatting/goodFiles
40+
exclude-dirs: ",,,"
41+
exclude-files: "errorFileInDirectory.h, formatErrorTest.h, errorFileInDirectory.c, formatErrorTest.c"
42+
43+
- name: Remove Error Files at Top Directory
44+
working-directory: formatting/goodFiles
45+
shell: bash
46+
run: |
47+
# Remove Error Files at Top Directory
48+
# Do a git remove since we use a git diff to check if formatting fails
49+
git rm $(find . -name "formatErrorTest.c")
50+
git rm $(find . -name "formatErrorTest.h")
51+
52+
- env:
53+
stepName: "Functional | Success | Exclude Just Error Dirs"
54+
name: ${{ env.stepName }}
55+
id: exclude-two-files-two-dirs
56+
uses: ./formatting
57+
with:
58+
path: formatting/goodFiles
59+
exclude-dirs: "fileWithErrorInclude, fileWithErrorSource"
60+
61+
formatting-error-cases:
62+
runs-on: ubuntu-20.04
63+
steps:
64+
- uses: actions/checkout@v3
65+
- env:
66+
stepName: "Functional | Failure | Whitespace, CRLF, and Format Failure"
67+
name: ${{ env.stepName }}
68+
id: all-format-errors
69+
continue-on-error: true
70+
uses: ./formatting
71+
with:
72+
path: formatting
73+
74+
- name: Reset Files
75+
shell: bash
76+
run: git reset --hard
77+
78+
- env:
79+
stepName: "Functional | Failure | CRLF and Formatting Error"
80+
name: ${{ env.stepName }}
81+
id: crlf-and-format-error
82+
continue-on-error: true
83+
uses: ./formatting
84+
with:
85+
path: formatting
86+
exclude-dirs: "filesWithTrailingWhitespace"
87+
88+
- name: Reset Files
89+
shell: bash
90+
run: git reset --hard
91+
92+
- env:
93+
stepName: "Functional | Failure | CRLF and Whitespace Error"
94+
name: ${{ env.stepName }}
95+
id: crlf-and-whitespace-error
96+
continue-on-error: true
97+
uses: ./formatting
98+
with:
99+
path: formatting
100+
exclude-dirs: "filesWithFormattingErrors"
101+
102+
- name: Reset Files
103+
shell: bash
104+
run: git reset --hard
105+
106+
- env:
107+
stepName: "Functional | Failure | CRLF and Whitespace Error Not C Files"
108+
name: ${{ env.stepName }}
109+
id: crlf-and-whitespace-non-c-error
110+
continue-on-error: true
111+
uses: ./formatting
112+
with:
113+
path: formatting
114+
exclude-dirs: "filesWithFormattingErrors, fileWithErrorInclude, fileWithErrorSource"
115+
116+
- name: Reset Files
117+
shell: bash
118+
run: git reset --hard
119+
120+
- env:
121+
stepName: "Functional | Failure | CRLF Error"
122+
name: ${{ env.stepName }}
123+
id: crlf-error
124+
continue-on-error: true
125+
uses: ./formatting
126+
with:
127+
path: formatting
128+
exclude-dirs: "filesWithFormattingErrors,filesWithTrailingWhitespace"
129+
exclude-files: "badFile.c"
130+
131+
- name: Reset Files
132+
shell: bash
133+
run: git reset --hard
134+
135+
- env:
136+
stepName: "Functional | Failure | Formatting and Whitespace Error"
137+
name: ${{ env.stepName }}
138+
id: formatting-and-whitespace-error
139+
continue-on-error: true
140+
uses: ./formatting
141+
with:
142+
path: formatting
143+
exclude-dirs: "filesWithCRLFEndings"
144+
145+
- name: Reset Files
146+
shell: bash
147+
run: git reset --hard
148+
149+
- env:
150+
stepName: "Functional | Failure | Formatting Error"
151+
name: ${{ env.stepName }}
152+
id: formatting-error
153+
continue-on-error: true
154+
uses: ./formatting
155+
with:
156+
path: formatting
157+
exclude-dirs: "filesWithTrailingWhitespace,filesWithCRLFEndings"
158+
159+
- name: Reset Files
160+
shell: bash
161+
run: git reset --hard
162+
163+
- env:
164+
stepName: "Functional | Failure | Whitespace Error"
165+
name: ${{ env.stepName }}
166+
id: whitespace-error
167+
continue-on-error: true
168+
uses: ./formatting
169+
with:
170+
path: formatting
171+
exclude-dirs: "filesWithFormattingErrors,filesWithCRLFEndings"
172+
173+
- name: Reset Files
174+
shell: bash
175+
run: git reset --hard
176+
177+
- env:
178+
stepName: "API | Failure | Exclude Dirs Error"
179+
name: ${{ env.stepName }}
180+
id: error-in-exclude-dirs
181+
continue-on-error: true
182+
uses: ./formatting
183+
with:
184+
path: formatting
185+
exclude-dirs: "filesWithFormattingErrors, filesWithCRLFEndings"
186+
187+
- name: Reset Files
188+
shell: bash
189+
run: git reset --hard
190+
191+
- env:
192+
stepName: "API | Failure | Exclude Files Error"
193+
name: ${{ env.stepName }}
194+
id: error-in-exclude-files
195+
continue-on-error: true
196+
uses: ./formatting
197+
with:
198+
path: formatting
199+
exclude-files: "filesWithFormattingErrors, filesWithCRLFEndings"
200+
201+
- name: Reset Files
202+
shell: bash
203+
run: git reset --hard
204+
205+
- env:
206+
stepName: "API | Failure | Exclude Option Errors"
207+
name: ${{ env.stepName }}
208+
id: error-in-both
209+
continue-on-error: true
210+
uses: ./formatting
211+
with:
212+
path: formatting
213+
exclude-files: "filesWithFormattingErrors, filesWithCRLFEndings"
214+
exclude-dirs: "filesWithFormattingErrors,
215+
filesWithCRLFEndings"
216+
217+
- name: Reset Files
218+
shell: bash
219+
run: git reset --hard
220+
221+
- env:
222+
stepName: Check Failure Test Cases
223+
name: ${{ env.stepName }}
224+
id: check-failure-test-cases
225+
shell: bash
226+
run: |
227+
# ${{ env.stepName }}
228+
exitStatus=0
229+
if [ "${{ steps.all-format-errors.outcome}}" = "failure" ]; then
230+
echo -e "${{ env.bashPass }} Functional | Failure | Whitespace, CRLF, and Format Failure | Had Expected "failure" ${{ env.bashEnd }}"
231+
else
232+
echo -e "${{ env.bashFail }} Functional | Failure | Whitespace, CRLF, and Format Failure | Had Unexpected "success" ${{ env.bashEnd }}"
233+
exitStatus=1
234+
fi
235+
if [ "${{ steps.crlf-and-format-error.outcome}}" = "failure" ]; then
236+
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Formatting Error | Had Expected "failure" ${{ env.bashEnd }}"
237+
else
238+
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Formatting Error | Had Unexpected "success" ${{ env.bashEnd }}"
239+
exitStatus=1
240+
fi
241+
if [ "${{ steps.crlf-and-whitespace-error.outcome}}" = "failure" ]; then
242+
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
243+
else
244+
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
245+
exitStatus=1
246+
fi
247+
if [ "${{ steps.crlf-and-whitespace-non-c-error.outcome}}" = "failure" ]; then
248+
echo -e "${{ env.bashPass }} Functional | Failure | CRLF and Whitespace Error Not C Files | Had Expected "failure" ${{ env.bashEnd }}"
249+
else
250+
echo -e "${{ env.bashFail }} Functional | Failure | CRLF and Whitespace Error Not C Files | Had Unexpected "success" ${{ env.bashEnd }}"
251+
exitStatus=1
252+
fi
253+
if [ "${{ steps.crlf-error.outcome}}" = "failure" ]; then
254+
echo -e "${{ env.bashPass }} Functional | Failure | CRLF Error | Had Expected "failure" ${{ env.bashEnd }}"
255+
else
256+
echo -e "${{ env.bashFail }} Functional | Failure | CRLF Error | Had Unexpected "success" ${{ env.bashEnd }}"
257+
exitStatus=1
258+
fi
259+
if [ "${{ steps.formatting-and-whitespace-error.outcome}}" = "failure" ]; then
260+
echo -e "${{ env.bashPass }} Functional | Failure | Formatting and Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
261+
else
262+
echo -e "${{ env.bashFail }} Functional | Failure | Formatting and Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
263+
exitStatus=1
264+
fi
265+
if [ "${{ steps.formatting-error.outcome}}" = "failure" ]; then
266+
echo -e "${{ env.bashPass }} Functional | Failure | Formatting Error | Had Expected "failure" ${{ env.bashEnd }}"
267+
else
268+
echo -e "${{ env.bashFail }} Functional | Failure | Formatting Error | Had Unexpected "success" ${{ env.bashEnd }}"
269+
exitStatus=1
270+
fi
271+
if [ "${{ steps.whitespace-error.outcome}}" = "failure" ]; then
272+
echo -e "${{ env.bashPass }} Functional | Failure | Whitespace Error | Had Expected "failure" ${{ env.bashEnd }}"
273+
else
274+
echo -e "${{ env.bashFail }} Functional | Failure | Whitespace Error | Had Unexpected "success" ${{ env.bashEnd }}"
275+
exitStatus=1
276+
fi
277+
if [ "${{ steps.error-in-exclude-dirs.outcome}}" = "failure" ]; then
278+
echo -e "${{ env.bashPass }} API | Failure | Exclude Dirs Error | Had Expected "failure" ${{ env.bashEnd }}"
279+
else
280+
echo -e "${{ env.bashFail }} API | Failure | Exclude Dirs Error | Had Unexpected "success" ${{ env.bashEnd }}"
281+
exitStatus=1
282+
fi
283+
if [ "${{ steps.error-in-exclude-files.outcome}}" = "failure" ]; then
284+
echo -e "${{ env.bashPass }} API | Failure | Exclude Files Error | Had Expected "failure" ${{ env.bashEnd }}"
285+
else
286+
echo -e "${{ env.bashFail }} API | Failure | Exclude Files Error | Had Unexpected "success" ${{ env.bashEnd }}"
287+
exitStatus=1
288+
fi
289+
if [ "${{ steps.error-in-both.outcome}}" = "failure" ]; then
290+
echo -e "${{ env.bashPass }} API | Failure | Exclude Option Errors | Had Expected "failure" ${{ env.bashEnd }}"
291+
else
292+
echo -e "${{ env.bashFail }} API | Failure | Exclude Option Errors | Had Unexpected "success" ${{ env.bashEnd }}"
293+
exitStatus=1
294+
fi
295+
exit $exitStatus

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
test-format-check:
1212
runs-on: ubuntu-20.04
1313
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v3
1616
with:
17-
repository: FreeRTOS/coreMQTT
18-
ref: main
17+
repository: Skptak/coreMQTT
18+
ref: CI-CD-Updates
1919
path: coreMQTT
2020
- name: Test formatting check action
2121
uses: ./formatting
@@ -109,7 +109,7 @@ jobs:
109109
exe-path: executable-monitor/test.out
110110
success-line: "SLEEPING FOR 6 SECONDS"
111111
timeout-seconds: 20
112-
112+
113113
- name: Functional Test | Success Case | No Retries, No Success Line, Exit Code
114114
id: test-executable-monitor-action-no-retry-attempts-exit-code
115115
uses: ./executable-monitor
@@ -125,7 +125,7 @@ jobs:
125125
exe-path: executable-monitor/test.out
126126
success-line: "SLEEPING FOR 6 SECONDS"
127127
retry-attempts: 2
128-
128+
129129
- name: API Test | Success Case | Retries, No Success Line, Exit Code, Use Default Timeout
130130
id: test-executable-monitor-action-no-success-line-no-timeout
131131
uses: ./executable-monitor
@@ -353,7 +353,7 @@ jobs:
353353
repository: FreeRTOS/FreeRTOS
354354
ref: '202107.00'
355355
path: FreeRTOS
356-
submodules: recursive
356+
submodules: recursive
357357
- name: Test manifest verifier
358358
uses: ./manifest-verifier
359359
with:

formatting/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Uncrustify Format GitHub Action
2+
## Purpose
3+
This directory contains an [action.yml](action.yml) file to uncrustify code
4+
files inside of [FreeRTOS](https://github.com/FreeRTOS/) repositories. It
5+
additionally will check for files with trailing whitespace, and CRLF line
6+
endings.
7+
8+
If a file is found that contains incorrect formatting, trailing whitespace, or
9+
CRLF endings, this action will create a Git Patch that will be added to the
10+
summary of the workflow run that uses this action. This allows an end user to
11+
download the patch, apply it, and then pass the formatting checks.
12+
13+
A patch is provided, instead of automatically applying the updates, as
14+
automatically formatting files could lead to merge conflicts. If an end-user
15+
didn't know they need to perform a `git pull` as their origin would have the
16+
formatting change applied.
17+
18+
## Testing Files
19+
This directory contains many files that are used to test the action.
20+
These tests can be found inside of
21+
[formattingTests.yml](../.github/workflows/formattingTests.yml).
22+
The files have been named in such a way to explain what their purpose is.
23+
The general idea is that there are a mix of files, some with CRLF endings,
24+
some with uncrustify errors, and some with trailing whitespace. Where the
25+
inside of
26+
[formattingTests.yml](../.github/workflows/formattingTests.yml)
27+
these various files are checked to ensure this action properly fails when
28+
a formatting issue is discovered. Additional tests are here to ensure that
29+
the various input parameters to the action work as intended.

0 commit comments

Comments
 (0)