-
Notifications
You must be signed in to change notification settings - Fork 7
252 lines (225 loc) · 7.56 KB
/
Copy pathpr-check.yml
File metadata and controls
252 lines (225 loc) · 7.56 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: PR Checks
on:
issue_comment:
types: [created]
jobs:
slash-command:
name: Parse /run-checks
if: >-
github.event.issue.pull_request != null &&
contains(github.event.comment.body, '/run-checks')
runs-on: ubuntu-latest
outputs:
pr-sha: ${{ steps.get-sha.outputs.sha }}
steps:
- name: Check commenter permission
uses: actions/github-script@v9
with:
script: |
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.actor,
});
if (!['admin', 'write'].includes(data.permission)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `@${context.actor} Only maintainers can trigger checks.`,
});
core.setFailed('Unauthorized');
}
- name: React with rocket
uses: actions/github-script@v9
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
content: 'rocket',
});
- name: Get PR head SHA
id: get-sha
uses: actions/github-script@v9
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
core.setOutput('sha', pr.head.sha);
- name: Set checks to pending
uses: actions/github-script@v9
with:
script: |
const sha = '${{ steps.get-sha.outputs.sha }}';
const checks = ['Lint', 'Build C++ (ubuntu-22.04)', 'Build C++ (ubuntu-24.04)', 'Build C++ (macos-14)', 'Validate'];
for (const check of checks) {
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha,
state: 'pending',
context: check,
description: 'Waiting...',
});
}
lint:
name: Lint
needs: slash-command
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.slash-command.outputs.pr-sha }}
- name: C++ format check
run: |
sudo apt-get install -y clang-format
find . -name "*.cpp" -o -name "*.h" | grep -v "build/" | \
xargs clang-format --dry-run --Werror || true
- name: Python lint (ruff)
uses: chartboost/ruff-action@v1
with:
args: "check engine/ --ignore E501 --exit-zero"
- name: Report status
if: always()
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.slash-command.outputs.pr-sha }}',
state: '${{ job.status }}' === 'success' ? 'success' : 'failure',
context: 'Lint',
description: '${{ job.status }}',
});
build-cpp:
name: Build C++ (${{ matrix.os }})
needs: slash-command
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, ubuntu-24.04, macos-14]
include:
- os: ubuntu-22.04
artifact: quadtrix-linux-x64
- os: ubuntu-24.04
artifact: quadtrix-linux-x64-noble
- os: macos-14
artifact: quadtrix-macos-arm64
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.slash-command.outputs.pr-sha }}
- name: Install GCC (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y g++ ccache
- name: Cache ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-${{ matrix.os }}-${{ hashFiles('**/*.cpp', '**/*.h') }}
restore-keys: ccache-${{ matrix.os }}-
- name: Compile main.cpp
run: |
g++ -std=c++17 -O3 -march=native \
-I. -Iinclude \
-o quadtrix main.cpp
- name: Smoke test
run: ./quadtrix --help || true
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: quadtrix
retention-days: 7
- name: Report status
if: always()
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.slash-command.outputs.pr-sha }}',
state: '${{ job.status }}' === 'success' ? 'success' : 'failure',
context: 'Build C++ (${{ matrix.os }})',
description: '${{ job.status }}',
});
validate:
name: Validate
needs: slash-command
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.slash-command.outputs.pr-sha }}
- name: Check required files exist
run: |
files=(
"main.cpp"
"engine/main.py"
"requirements.txt"
)
failed=0
for f in "${files[@]}"; do
if [ -f "$f" ]; then
echo "✅ $f"
else
echo "❌ $f — MISSING"
failed=1
fi
done
exit $failed
- name: Lint — Dockerfile.cpp
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: .devops/Dockerfile.cpp
failure-threshold: error
- name: Lint — Dockerfile (CPU)
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: .devops/Dockerfile
failure-threshold: error
- name: Lint — Dockerfile.backend (CUDA)
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: .devops/Dockerfile.backend
failure-threshold: error
- name: Report status
if: always()
uses: actions/github-script@v9
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.slash-command.outputs.pr-sha }}',
state: '${{ job.status }}' === 'success' ? 'success' : 'failure',
context: 'Validate',
description: '${{ job.status }}',
});
post-result:
name: Post result
needs: [slash-command, lint, build-cpp, validate]
runs-on: ubuntu-latest
if: always()
steps:
- uses: actions/github-script@v9
with:
script: |
const jobs = ${{ toJSON(needs) }};
const failed = Object.values(jobs).some(j => j.result === 'failure');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: failed
? '❌ Some checks failed — see Actions for details.'
: '✅ All checks passed!',
});