Skip to content

Commit b1c2f94

Browse files
Fix the run-clang-format workflow for real this time (#601)
* Here we go again * I forgot git clang-format sets the exit code... * Testing to see if I can get this to run in a PR * See if it runs now * Try with powershell * Test to see if this pushes to my branch * Run clang-format on PR changes * Remove the PR "hack" --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2b52c86 commit b1c2f94

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

.github/workflows/format.yml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
outputs:
2727
pr-ref: ${{ steps.pr.outputs.ref }}
2828
pr-sha: ${{ steps.pr.outputs.sha }}
29-
has-changes: ${{ steps.check-changes.outputs.has-changes }}
29+
has-changes: ${{ steps.format.outputs.has-changes }}
3030

3131
steps:
3232
- name: Get PR info
@@ -51,33 +51,31 @@ jobs:
5151
- name: Fetch PR branch
5252
shell: cmd
5353
run: |
54-
git fetch origin ${{ steps.pr.outputs.ref }}:pr-branch
55-
git checkout pr-branch
54+
git fetch origin ${{ steps.pr.outputs.ref }}
55+
git checkout ${{ steps.pr.outputs.ref }}
5656
5757
- name: Run clang-format
5858
id: format
59-
shell: cmd
60-
run: |
61-
REM 'run-clang-format' script needs 'VCINSTALLDIR' env (among maybe others) to be set
62-
call ./scripts/call-vcvars.cmd x64
63-
call ./scripts/format-changes.cmd origin/master
64-
65-
- name: Check for changes
66-
id: check-changes
67-
shell: cmd
59+
shell: pwsh
6860
run: |
69-
git diff --quiet && echo has-changes=false>> %GITHUB_OUTPUT% || echo has-changes=true>> %GITHUB_OUTPUT%
70-
REM Don't let the exit code of 'git diff' cause this step to fail
71-
exit /b 0
61+
# 'run-clang-format' script needs 'VCINSTALLDIR' env (among maybe others) to be set
62+
& cmd /c "call ./scripts/call-vcvars.cmd x64 && call ./scripts/format-changes.cmd origin/master"
63+
if ($LASTEXITCODE -eq 0) {
64+
"has-changes=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -NoNewline
65+
} else {
66+
"has-changes=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -NoNewline
67+
}
68+
# Don't let the exit code of 'git clang-format' cause this step to fail
69+
exit 0
7270
7371
- name: Create patch
74-
if: steps.check-changes.outputs.has-changes == 'true'
72+
if: steps.format.outputs.has-changes == 'true'
7573
shell: cmd
7674
run: |
7775
git diff > format-changes.patch
7876
7977
- name: Upload patch
80-
if: steps.check-changes.outputs.has-changes == 'true'
78+
if: steps.format.outputs.has-changes == 'true'
8179
uses: actions/upload-artifact@v4
8280
with:
8381
name: format-patch
@@ -102,8 +100,8 @@ jobs:
102100
- name: Fetch PR branch
103101
shell: cmd
104102
run: |
105-
git fetch origin ${{ needs.format-code.outputs.pr-ref }}:pr-branch
106-
git checkout pr-branch
103+
git fetch origin ${{ needs.format-code.outputs.pr-ref }}
104+
git checkout ${{ needs.format-code.outputs.pr-ref }}
107105
108106
- name: Download patch
109107
uses: actions/download-artifact@v4
@@ -114,6 +112,7 @@ jobs:
114112
shell: cmd
115113
run: |
116114
git apply format-changes.patch
115+
del format-changes.patch
117116
118117
- name: Commit and push changes
119118
shell: cmd
@@ -122,7 +121,7 @@ jobs:
122121
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
123122
git add -A
124123
git commit -m "Run clang-format on PR changes"
125-
git push origin pr-branch
124+
git push origin HEAD:${{ needs.format-code.outputs.pr-ref }}
126125
127126
# Job 3: Comment on PR with results
128127
comment-result:

0 commit comments

Comments
 (0)