|
7 | 7 | jobs: |
8 | 8 | ClangFormat: |
9 | 9 | runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
10 | 12 | steps: |
11 | 13 | - name: Checkout |
12 | | - uses: actions/checkout@v3 |
| 14 | + uses: actions/checkout@v4 |
13 | 15 | - name: Fetch git |
14 | 16 | run: git fetch --no-tags -fu origin develop:develop |
15 | 17 | - name: Run Clang-Format-Diff.py |
| 18 | + id: clang-format |
16 | 19 | run: | |
17 | 20 | git diff -U0 origin/develop -- $(git ls-files -- $(cat test/util/data/non-backported.txt)) | ./contrib/devtools/clang-format-diff.py -p1 > diff_output.txt |
18 | 21 | if [ -s diff_output.txt ]; then |
19 | | - echo "Clang format differences found:" |
20 | | - cat diff_output.txt |
21 | | - exit 1 |
| 22 | + echo "::warning::Clang format differences found. See PR comment for details." |
| 23 | + echo "has_diff=true" >> "$GITHUB_OUTPUT" |
22 | 24 | else |
23 | 25 | echo "No Clang format differences found." |
| 26 | + echo "has_diff=false" >> "$GITHUB_OUTPUT" |
24 | 27 | fi |
| 28 | + - name: Build comment body |
| 29 | + if: steps.clang-format.outputs.has_diff == 'true' |
| 30 | + run: | |
| 31 | + { |
| 32 | + echo "<!-- clang-format-check -->" |
| 33 | + echo "⚠️ Clang Format Diff Check" |
| 34 | + echo "---" |
| 35 | + echo "" |
| 36 | + echo "Formatting issues were found in this PR." |
| 37 | + echo "" |
| 38 | + echo "<details><summary>Click to expand diff</summary>" |
| 39 | + echo "" |
| 40 | + echo '```diff' |
| 41 | + cat diff_output.txt |
| 42 | + echo '```' |
| 43 | + echo "" |
| 44 | + echo "</details>" |
| 45 | + } > comment_body.txt |
| 46 | + - name: Find existing comment |
| 47 | + uses: peter-evans/find-comment@v3 |
| 48 | + id: fc |
| 49 | + with: |
| 50 | + issue-number: ${{ github.event.pull_request.number }} |
| 51 | + comment-author: 'github-actions[bot]' |
| 52 | + body-includes: '<!-- clang-format-check -->' |
| 53 | + - name: Post or update comment |
| 54 | + if: steps.clang-format.outputs.has_diff == 'true' |
| 55 | + uses: peter-evans/create-or-update-comment@v5 |
| 56 | + with: |
| 57 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 58 | + issue-number: ${{ github.event.pull_request.number }} |
| 59 | + edit-mode: replace |
| 60 | + body-path: comment_body.txt |
| 61 | + - name: Update comment as resolved |
| 62 | + if: steps.clang-format.outputs.has_diff == 'false' && steps.fc.outputs.comment-id != '' |
| 63 | + uses: peter-evans/create-or-update-comment@v5 |
| 64 | + with: |
| 65 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 66 | + edit-mode: replace |
| 67 | + body: | |
| 68 | + <!-- clang-format-check --> |
| 69 | + ✅ Clang Format Diff Check |
| 70 | + --- |
| 71 | +
|
| 72 | + No formatting issues found. |
0 commit comments