Skip to content

Commit 75d799f

Browse files
Trippable CI/CD Auto Format (#545)
# Casually Invokable Auto Formatting ## Problem and Scope I catch myself mark a PR as ready for review and then setting it back to a draft after all the auto formatting jobs ran just because it's nice to have ## Description Run auto format only on commits with the lowercase words `auto` and `format` in them OR when in a pr that is not a draft ## Gotchas and Limitations Later auto formatting jobs invoke off of it, which is intentional, but could be confusing ## Testing - [ ] HOOTL testing - [ ] HITL testing - [x] Human tested ### Testing Details Tried different combinations as commits within this PR ## Larger Impact Nicer setup and no pinging on ready for review boundaries ## Additional Context and Ticket Thought of during #526 Resolves #541 --------- Signed-off-by: Daniel Hansen <dchansen06@gmail.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b92968c commit 75d799f

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

.github/workflows/AutoFormat.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,34 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13+
conditional:
14+
name: Conditional Formatting Check
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
outputs:
19+
run_format: ${{ steps.conditional_check.outputs.run_format }}
20+
steps:
21+
- name: Checkout Pull Request
22+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23+
with:
24+
fetch-depth: 1
25+
ref: ${{ github.event.pull_request.head.ref }}
26+
27+
- name: Conditional Check
28+
id: conditional_check
29+
run: |
30+
if [ "${{ github.event.pull_request.draft }}" != "true" ]; then
31+
echo "run_format=true" >> "$GITHUB_OUTPUT"
32+
elif git log -1 --pretty=%B | grep -iq "format"; then
33+
echo "run_format=true" >> "$GITHUB_OUTPUT"
34+
else
35+
echo "run_format=false" >> "$GITHUB_OUTPUT"
36+
fi
37+
1338
clang:
14-
if: ${{ !github.event.pull_request.draft }}
39+
needs: conditional
40+
if: ${{ needs.conditional.outputs.run_format == 'true' }}
1541
name: Clang
1642
runs-on: ubuntu-latest
1743
permissions:
@@ -36,7 +62,7 @@ jobs:
3662
echo "<details open><summary>Clang-Format Output</summary>" >> $GITHUB_STEP_SUMMARY
3763
echo "" >> $GITHUB_STEP_SUMMARY
3864
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
39-
git ls-files '*.c' '*.h' | xargs -r clang-format -i --verbose 2>&1 | tee -a $GITHUB_STEP_SUMMARY
65+
git ls-files '*.c' '*.h' | parallel clang-format -i --verbose 2>&1 | tee -a $GITHUB_STEP_SUMMARY
4066
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
4167
echo "" >> $GITHUB_STEP_SUMMARY
4268
echo "</details>" >> $GITHUB_STEP_SUMMARY
@@ -52,7 +78,8 @@ jobs:
5278
fetch: "false"
5379

5480
cmake:
55-
if: ${{ !github.event.pull_request.draft }}
81+
needs: conditional
82+
if: ${{ needs.conditional.outputs.run_format == 'true' }}
5683
name: CMake
5784
runs-on: ubuntu-slim
5885
permissions:
@@ -90,7 +117,8 @@ jobs:
90117
fetch: "false"
91118

92119
json:
93-
if: ${{ !github.event.pull_request.draft }}
120+
needs: conditional
121+
if: ${{ needs.conditional.outputs.run_format == 'true' }}
94122
name: Json
95123
runs-on: ubuntu-slim
96124
permissions:
@@ -125,7 +153,8 @@ jobs:
125153
fetch: "false"
126154

127155
perl:
128-
if: ${{ !github.event.pull_request.draft }}
156+
needs: conditional
157+
if: ${{ needs.conditional.outputs.run_format == 'true' }}
129158
name: Perl
130159
runs-on: ubuntu-slim
131160
permissions:
@@ -165,7 +194,8 @@ jobs:
165194
fetch: "false"
166195

167196
asm:
168-
if: ${{ !github.event.pull_request.draft }}
197+
needs: conditional
198+
if: ${{ needs.conditional.outputs.run_format == 'true' }}
169199
name: Assembly
170200
runs-on: ubuntu-slim
171201
permissions:

Lib/Platform/STM32G474xE/startup_stm32g474xx.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,4 +593,3 @@ g_pfnVectors:
593593

594594
.weak FMAC_IRQHandler
595595
.thumb_set FMAC_IRQHandler,Default_Handler
596-

Lib/Platform/STM32L476xG/startup_stm32l476xx.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,3 @@ g_pfnVectors:
511511

512512
.weak FPU_IRQHandler
513513
.thumb_set FPU_IRQHandler,Default_Handler
514-

0 commit comments

Comments
 (0)