-
Notifications
You must be signed in to change notification settings - Fork 48
494 lines (441 loc) · 18.8 KB
/
ci-pr-checks.yaml
File metadata and controls
494 lines (441 loc) · 18.8 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
name: CI - PR Checks
# Cancel previous runs on the same PR when new commits are pushed
# Group by PR number for pull_request and /ok-to-test comment triggers
# Regular comments get a unique group (run_id) so they don't cancel in-progress test runs
# workflow_dispatch falls back to run_id (no PR number available)
#
# Logic:
# - Regular comments (not /ok-to-test): unique group prevents cancellation of real tests
# - pull_request / /ok-to-test comments: group 'ci-pr-checks-{pr_number}' (can cancel previous runs for same PR)
# - workflow_dispatch: group 'ci-pr-checks-{run_id}' (unique per run)
# - Fallback chain for ID: pull_request.number -> issue.number -> run_id
#
# NOTE: Accepted command (/ok-to-test) must stay in sync with check-full-tests job validation
concurrency:
group: >-
${{
github.event_name == 'issue_comment' &&
!contains(github.event.comment.body, '/ok-to-test')
&& format('comment-isolated-{0}', github.run_id)
|| format('ci-pr-checks-{0}',
github.event.pull_request.number
|| github.event.issue.number
|| github.run_id)
}}
cancel-in-progress: true
on:
pull_request:
branches:
- main
- dev
# Allow manual triggering of full e2e tests
workflow_dispatch:
inputs:
run_full_tests:
description: 'Run full e2e test suite on Kind (check to run full; unchecked runs no e2e)'
required: false
default: false
type: boolean
# Allow triggering via /ok-to-test PR comment
issue_comment:
types: [created]
jobs:
# Check if PR contains code changes (not just docs/metadata)
check-code-changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read # For reading PR details when triggered via issue_comment
outputs:
has_code_changes: ${{ steps.set-output.outputs.has_code_changes }}
pr_head_sha: ${{ steps.pr-info.outputs.pr_head_sha }}
pr_head_repo: ${{ steps.pr-info.outputs.pr_head_repo }}
steps:
- name: Get PR number for issue_comment events
id: pr-info
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
if (!issue.pull_request) {
core.setOutput('pr_number', '');
return;
}
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
const baseRepo = `${context.repo.owner}/${context.repo.repo}`;
const headRepo = pr.head.repo ? pr.head.repo.full_name : baseRepo;
core.setOutput('pr_number', issue.number.toString());
core.setOutput('pr_head_sha', pr.head.sha);
core.setOutput('pr_head_repo', headRepo);
- name: Checkout source
uses: actions/checkout@v4
with:
# For issue_comment on a fork PR: checkout from head repo so the commit exists
repository: ${{ steps.pr-info.outputs.pr_head_repo || github.repository }}
ref: ${{ github.event_name == 'issue_comment' && steps.pr-info.outputs.pr_head_sha || github.event.pull_request.head.sha || github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Check for code changes
uses: dorny/paths-filter@v3
id: filter
continue-on-error: true # Don't fail if paths-filter can't determine changes (e.g., issue_comment without PR context)
with:
filters: |
code:
- '!docs/**'
- '!README.md'
- '!CONTRIBUTING.md'
- '!LICENSE'
- '!OWNERS'
- '!PROJECT'
- name: Set output with default
id: set-output
run: |
# Use filter output if available, otherwise default to 'true' for issue_comment events
# This ensures comment triggers work even if PR context is unclear
FILTER_OUTPUT="${{ steps.filter.outputs.code }}"
if [ "${{ github.event_name }}" == "issue_comment" ] && [ -z "$FILTER_OUTPUT" ]; then
echo "has_code_changes=true" >> $GITHUB_OUTPUT
elif [ -n "$FILTER_OUTPUT" ]; then
echo "has_code_changes=$FILTER_OUTPUT" >> $GITHUB_OUTPUT
else
echo "has_code_changes=true" >> $GITHUB_OUTPUT
fi
# lint-and-test already runs on pull_request events; skip for issue_comment
# to avoid untrusted commenters triggering execution of PR code
lint-and-test:
if: github.event_name != 'issue_comment'
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Sanity check repo contents
run: ls -la
- name: Extract Go version from go.mod
run: sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go with cache
uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: ./go.sum
- name: Install dependencies
run: go mod download
- name: Install golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.8.0
args: ""
- name: Run make build
shell: bash
run: |
make build
- name: Run make test
shell: bash
run: |
make test
# Check if full e2e tests should run (via workflow_dispatch or comment trigger)
check-full-tests:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # For posting comments and reactions on PRs
outputs:
run_full: ${{ steps.check.outputs.run_full }}
steps:
- name: Check if full tests requested
id: check
uses: actions/github-script@v7
with:
script: |
// Helper to check if user has write access
async function hasWriteAccess(username) {
try {
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: username
});
const privilegedRoles = ['admin', 'maintain', 'write'];
return privilegedRoles.includes(permission.permission);
} catch (e) {
console.log(`Could not get permissions for ${username}: ${e.message}`);
return false;
}
}
// Check workflow_dispatch input
const workflowInput = '${{ github.event.inputs.run_full_tests }}';
// Handle both boolean and string inputs
if (workflowInput === 'true' || workflowInput === true || workflowInput === 'True') {
core.setOutput('run_full', 'true');
return;
}
// Check for /ok-to-test comment trigger
if (context.eventName === 'issue_comment') {
const comment = context.payload.comment.body.trim();
const issue = context.payload.issue;
// Only process /ok-to-test comments on PRs
if (!issue.pull_request) {
console.log('Comment is not on a PR, skipping');
core.setOutput('run_full', 'false');
return;
}
// Accept /ok-to-test (same command triggers both Kind full E2E and OpenShift E2E)
const validCommands = ['/ok-to-test'];
if (!validCommands.includes(comment)) {
console.log(`Comment "${comment}" is not a valid trigger command, skipping`);
core.setOutput('run_full', 'false');
return;
}
// Check if commenter has write access
const commenter = context.payload.comment.user.login;
const hasAccess = await hasWriteAccess(commenter);
if (!hasAccess) {
console.log(`User ${commenter} does not have write access, ignoring ${comment}`);
core.setOutput('run_full', 'false');
return;
}
// Get PR details
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
console.log(`${comment} approved by ${commenter} for PR #${issue.number}`);
console.log(`PR head SHA: ${pr.head.sha}`);
// Add reaction to acknowledge
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
// Post comment with link to the workflow run
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `🚀 **Kind E2E (full)** triggered by \`/ok-to-test\`\n\n[View the Kind E2E workflow run](${runUrl})`
});
core.setOutput('run_full', 'true');
return;
}
core.setOutput('run_full', 'false');
# E2E smoke tests - run automatically on every PR with code changes
# Skip if PR only contains docs/metadata changes
e2e-tests-smoke:
runs-on: ubuntu-latest
needs: [lint-and-test, check-code-changes, check-full-tests]
if: github.event_name == 'pull_request' && needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true'
timeout-minutes: 60
permissions:
contents: read
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Extract Go version from go.mod
run: sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go with cache
uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: ./go.sum
- name: Install dependencies
run: go mod download
- name: Install Kind
run: |
ARCH=$(uname -m)
case "$ARCH" in
x86_64) KIND_ARCH="amd64" ;;
aarch64) KIND_ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-${KIND_ARCH}"
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build WVA image locally
id: build-image
env:
CHECKOUT_SHA: ${{ needs.check-code-changes.outputs.pr_head_sha || github.sha }}
run: |
# Generate unique image tag for this PR run (local image, no registry needed)
IMAGE_NAME="llm-d-workload-variant-autoscaler"
IMAGE_TAG="pr-${GITHUB_RUN_ID}-${CHECKOUT_SHA:0:7}"
# Use localhost prefix for local-only image (Kind will load it directly)
FULL_IMAGE="localhost/${IMAGE_NAME}:${IMAGE_TAG}"
echo "Building local image: $FULL_IMAGE"
echo "Image will be loaded into Kind cluster (no push needed)"
# Build image locally (no push needed for Kind)
make docker-build IMG="$FULL_IMAGE"
echo "image=$FULL_IMAGE" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "Image built locally: $FULL_IMAGE"
- name: Run e2e tests (smoke)
shell: bash
env:
ENVIRONMENT: kind-emulator
USE_SIMULATOR: "true"
SCALE_TO_ZERO_ENABLED: "false"
CREATE_CLUSTER: "true"
INSTALL_GATEWAY_CTRLPLANE: "true"
E2E_TESTS_ENABLED: "true"
IMG: ${{ steps.build-image.outputs.image }}
SKIP_BUILD: "true"
PROMETHEUS_ADAPTER_WAIT: "false"
DELETE_CLUSTER: "true"
# Lower saturation thresholds for simulator mode — the simulator's
# KV-cache and queue metrics are modest, so default thresholds
# (kvSpareTrigger=0.1, queueSpareTrigger=3) are too high to trigger
# scale-up reliably. These values trigger when kvUsage > 0.30 or
# queueLength > 0.5, which the simulator produces under load.
KV_SPARE_TRIGGER: "0.5"
QUEUE_SPARE_TRIGGER: "4.5"
run: |
make test-e2e-smoke-with-setup
# Full Kind E2E - runs only when triggered (/ok-to-test or workflow_dispatch with run_full_tests).
# Add "e2e-tests-full" as a required status check in branch protection so it appears on every PR
# and must run and pass before merge (shows as "Expected" until triggered).
e2e-tests-full:
runs-on: ubuntu-latest
needs: [lint-and-test, check-code-changes, check-full-tests]
if: >-
always() && needs.check-full-tests.outputs.run_full == 'true' && needs.check-code-changes.result == 'success'
&& (github.event_name == 'issue_comment' || github.event_name == 'workflow_dispatch')
timeout-minutes: 60
permissions:
contents: read
statuses: write
steps:
- name: Set pending status on PR head
if: github.event_name == 'issue_comment' && needs.check-code-changes.outputs.pr_head_sha != ''
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.check-code-changes.outputs.pr_head_sha }}',
state: 'pending',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Full E2E tests running...',
context: '${{ github.workflow }} / e2e (comment trigger)'
});
- name: Validate PR head SHA for issue_comment events
if: github.event_name == 'issue_comment'
run: |
if [ -z "${{ needs.check-code-changes.outputs.pr_head_sha }}" ]; then
echo "::error::pr_head_sha is empty — refusing to fall back to main"
exit 1
fi
echo "Checkout will use PR head SHA: ${{ needs.check-code-changes.outputs.pr_head_sha }}"
echo "PR head repo: ${{ needs.check-code-changes.outputs.pr_head_repo || github.repository }}"
- name: Checkout source
uses: actions/checkout@v4
with:
repository: ${{ needs.check-code-changes.outputs.pr_head_repo || github.repository }}
ref: ${{ needs.check-code-changes.outputs.pr_head_sha || github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Go version from go.mod
run: sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- name: Set up Go with cache
uses: actions/setup-go@v6
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: ./go.sum
- name: Install dependencies
run: go mod download
- name: Install Kind
run: |
ARCH=$(uname -m)
case "$ARCH" in
x86_64) KIND_ARCH="amd64" ;;
aarch64) KIND_ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-${KIND_ARCH}"
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
kind version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build WVA image locally
id: build-image
env:
CHECKOUT_SHA: ${{ needs.check-code-changes.outputs.pr_head_sha || github.sha }}
run: |
IMAGE_NAME="llm-d-workload-variant-autoscaler"
IMAGE_TAG="pr-${GITHUB_RUN_ID}-${CHECKOUT_SHA:0:7}"
FULL_IMAGE="localhost/${IMAGE_NAME}:${IMAGE_TAG}"
echo "Building local image: $FULL_IMAGE"
make docker-build IMG="$FULL_IMAGE"
echo "image=$FULL_IMAGE" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Run e2e tests (full)
shell: bash
env:
ENVIRONMENT: kind-emulator
USE_SIMULATOR: "true"
SCALE_TO_ZERO_ENABLED: "true"
CREATE_CLUSTER: "true"
INSTALL_GATEWAY_CTRLPLANE: "true"
E2E_TESTS_ENABLED: "true"
IMG: ${{ steps.build-image.outputs.image }}
SKIP_BUILD: "true"
PROMETHEUS_ADAPTER_WAIT: "false"
DELETE_CLUSTER: "false"
KV_SPARE_TRIGGER: "0.5"
QUEUE_SPARE_TRIGGER: "4.5"
run: |
make test-e2e-full-with-setup
# Report status back to PR for issue_comment triggered runs
# This ensures fork PRs show the correct status after /ok-to-test runs complete
report-status:
runs-on: ubuntu-latest
needs: [check-code-changes, check-full-tests, e2e-tests-full]
if: always() && github.event_name == 'issue_comment' && needs.check-full-tests.outputs.run_full == 'true'
permissions:
statuses: write
steps:
- name: Report status to PR
uses: actions/github-script@v7
with:
script: |
const prHeadSha = '${{ needs.check-code-changes.outputs.pr_head_sha }}';
const e2eResult = '${{ needs.e2e-tests-full.result }}';
if (!prHeadSha) {
console.log('No PR head SHA available, skipping status report');
return;
}
let state, description;
if (e2eResult === 'success') {
state = 'success';
description = 'E2E tests passed';
} else if (e2eResult === 'skipped') {
state = 'failure';
description = 'E2E tests did not run (prerequisite failed or skipped)';
} else if (e2eResult === 'cancelled') {
state = 'failure';
description = 'E2E tests cancelled';
} else {
state = 'failure';
description = 'E2E tests failed';
}
console.log(`Reporting status to PR commit ${prHeadSha}: ${state} - ${description}`);
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: prHeadSha,
state: state,
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: description,
context: '${{ github.workflow }} / e2e (comment trigger)'
});
console.log('Status reported successfully');