-
Notifications
You must be signed in to change notification settings - Fork 5
94 lines (79 loc) · 2.93 KB
/
Copy pathformat.yml
File metadata and controls
94 lines (79 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Clang-Format Lint Check
on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
clang-format-check:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format-19
- name: Find unformatted files
id: format_check
run: |
FILE_LIST="unformatted_files.txt"
find solvers include ! -path 'src/third_party/*' \
-regex '.*\.\(cpp\|hpp\|h\|c\|cc\|cu\|cuh\)' \
-exec bash -c 'clang-format-19 -style=file -output-replacements-xml "$0" | grep -q "<replacement " && echo "$0"' {} \; > "$FILE_LIST"
cat "$FILE_LIST"
if [ -s "$FILE_LIST" ]; then
echo "failed=true" >> $GITHUB_ENV
{
echo 'files<<EOF'
cat "$FILE_LIST"
echo 'EOF'
} >> "$GITHUB_OUTPUT"
else
echo "failed=false" >> $GITHUB_ENV
echo 'files=' >> "$GITHUB_OUTPUT"
fi
- name: Find existing clang-format comment
id: find_comment
uses: peter-evans/find-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- clang-format-check -->'
- name: Create or update PR comment - failed
if: env.failed == 'true'
uses: peter-evans/create-or-update-comment@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
edit-mode: replace
body: |
<!-- clang-format-check -->
⚠️ **Clang-format check failed**
The following files are not correctly formatted:
```
${{ steps.format_check.outputs.files }}
```
Please run:
```bash
clang-format -i <file(s)>
```
And commit the changes before merging.
- name: Create or update PR comment - success
if: env.failed == 'false'
uses: peter-evans/create-or-update-comment@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
edit-mode: replace
body: |
<!-- clang-format-check -->
✅ **Linter reported no issues**
All C/C++ files are correctly formatted with **clang-format**.
- name: Fail job if formatting issues found
if: env.failed == 'true'
run: |
echo "❌ Formatting issues detected. Failing the job."
exit 1