-
Notifications
You must be signed in to change notification settings - Fork 2
368 lines (333 loc) · 14.4 KB
/
Copy pathrelease.yml
File metadata and controls
368 lines (333 loc) · 14.4 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
name: Build and Push Docker Image
on:
release:
types: [published]
workflow_dispatch:
# Default to read-all at top level; each job below escalates only the narrow
# scopes it actually needs (contents:write for benchmark history,
# packages:write + security-events:write for the Docker push + SARIF upload,
# packages:read for the smoke test pull).
permissions: read-all
jobs:
# Performance regression gate. Runs the benchmark profile three times,
# medians the results, then compares against the benchmark-data rolling
# history median. On regression (> 25% worse on any headline metric),
# fails the release before any Docker build runs. The rolling baseline keeps
# a single unusually fast shared-runner sample from becoming the only release
# comparison point; baseline.json remains updated for reference/bootstrap.
#
# Bypass: include `[benchmark-skip]` anywhere in the release notes body
# (for test-only / infra-only releases where benchmarks only measure
# environmental noise — precedent: v0.1.25.9, .10, .11 were all
# legitimately benchmark-skip'd).
#
# On successful non-bypass gate, atomically updates baseline.json
# with the new numbers and commits to main.
benchmark-gate:
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: write # needed to push updated baseline.json
outputs:
skipped: ${{ steps.decide.outputs.skipped }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.release.tag_name || github.ref }}
# Decide whether to run the gate. Skip for workflow_dispatch (manual
# Docker re-builds don't need regression check — the tag is already
# pinned). Skip also if [benchmark-skip] in release notes.
- name: Decide skip
id: decide
env:
EVENT: ${{ github.event_name }}
RELEASE_BODY: ${{ github.event.release.body }}
run: |
if [ "$EVENT" != "release" ]; then
echo "Event is '$EVENT' (not 'release') — skipping benchmark gate."
echo "skipped=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if echo "$RELEASE_BODY" | grep -qF "[benchmark-skip]"; then
echo "Release notes contain [benchmark-skip] — skipping benchmark gate."
echo "skipped=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Running benchmark gate."
echo "skipped=false" >> "$GITHUB_OUTPUT"
- name: Set up JDK 21
if: steps.decide.outputs.skipped == 'false'
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: 21
cache: maven
- name: Set up Python
if: steps.decide.outputs.skipped == 'false'
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.12'
# Reactor install first (release-workflow memory gotcha: benchmarks
# need the new version in ~/.m2 before -Pbenchmark can resolve it).
- name: Install reactor
if: steps.decide.outputs.skipped == 'false'
run: |
mvn -B install -DskipTests --file cycles-protocol-service/pom.xml
rm -rf cycles-protocol-service/cycles-protocol-service-api/target/surefire-reports
- name: Benchmark trials (3×)
if: steps.decide.outputs.skipped == 'false'
run: |
for i in 1 2 3; do
mvn -B test -Pbenchmark \
--file cycles-protocol-service/pom.xml \
-pl cycles-protocol-service-api
python3 scripts/parse-benchmarks.py \
cycles-protocol-service/cycles-protocol-service-api/target/surefire-reports \
--trial-of $i \
--tag "${{ github.event.release.tag_name || '' }}" \
> /tmp/trial${i}.json
echo "--- trial $i ---"
cat /tmp/trial${i}.json
rm -rf cycles-protocol-service/cycles-protocol-service-api/target/surefire-reports
done
- name: Median-aggregate
if: steps.decide.outputs.skipped == 'false'
run: |
python3 scripts/median-benchmarks.py /tmp/trial1.json /tmp/trial2.json /tmp/trial3.json \
> /tmp/current.json
echo '--- release candidate ---'
cat /tmp/current.json
# History + baseline live on the `benchmark-data` branch (not main).
# Branch protection on main rejects bot pushes; the dedicated
# non-protected branch pattern avoids needing bypass config or PAT
# secrets. See benchmarks/README.md on main for the full rationale.
- name: Fetch benchmark-data branch (worktree)
if: steps.decide.outputs.skipped == 'false'
run: |
git fetch origin benchmark-data:benchmark-data
git worktree add bench-data benchmark-data
- name: Regression check
if: steps.decide.outputs.skipped == 'false'
shell: bash
run: |
# pipefail so the non-zero exit from check-regression (on
# regression) isn't swallowed by `tee`.
set -o pipefail
python3 scripts/check-regression.py release \
--current /tmp/current.json \
--baseline bench-data/benchmarks/baseline.json \
--history bench-data/benchmarks/history.jsonl \
--window 7 \
--threshold 0.25 \
| tee /tmp/gate-summary.md
- name: Attach summary to job
if: steps.decide.outputs.skipped == 'false' && always()
run: |
if [ -f /tmp/gate-summary.md ]; then
cat /tmp/gate-summary.md >> "$GITHUB_STEP_SUMMARY"
fi
# On successful gate, the new median becomes the baseline for the
# next release. Also appended to history.jsonl for trend continuity.
# All writes go to the benchmark-data branch; main is untouched.
- name: Update baseline + history on benchmark-data
if: steps.decide.outputs.skipped == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
cp /tmp/current.json bench-data/benchmarks/baseline.json
cat /tmp/current.json >> bench-data/benchmarks/history.jsonl
echo "" >> bench-data/benchmarks/history.jsonl
cd bench-data
git add benchmarks/baseline.json benchmarks/history.jsonl
if git diff --cached --quiet; then
echo "no baseline/history changes to commit"
exit 0
fi
git commit -m "chore(bench): update baseline for ${{ github.event.release.tag_name }}
[skip ci]"
git push origin benchmark-data
build-and-push:
needs: benchmark-gate
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
security-events: write # for Trivy SARIF upload to Security tab
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Extract version from POM
id: version
run: |
VERSION=$(sed -n 's/.*<revision>\(.*\)<\/revision>.*/\1/p' cycles-protocol-service/pom.xml | tr -d ' ')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION"
- name: Log in to GHCR
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
# Two-phase build: load image locally for Trivy first, then push only
# if scan passes. Second build-push-action call is a cache hit (~5-10s
# rebuild + push) thanks to type=gha cache from the first call.
- name: Build image (no push, load for scan)
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
with:
context: .
push: false
load: true
tags: ghcr.io/runcycles/cycles-server:${{ steps.version.outputs.version }}
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Trivy vulnerability scan
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: ghcr.io/runcycles/cycles-server:${{ steps.version.outputs.version }}
severity: 'HIGH,CRITICAL'
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
exit-code: '1'
# In `format: sarif` mode the action builds an all-severities report
# by default, so `exit-code: 1` trips on ANY fixable finding and the
# `severity` filter above is ignored for gating. Limit the SARIF to
# the declared severities so the gate (and the Security-tab report)
# honor HIGH,CRITICAL only — a fixable MEDIUM should not block the
# release. See AUDIT.md (jackson-databind CVE-2026-54515).
limit-severities-for-sarif: true
- name: Upload Trivy SARIF to Security tab
if: always()
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4
with:
sarif_file: 'trivy-results.sarif'
category: trivy-container
- name: Push image (cache hit from first build)
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
with:
context: .
push: true
tags: |
ghcr.io/runcycles/cycles-server:${{ steps.version.outputs.version }}
ghcr.io/runcycles/cycles-server:latest
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set package visibility to public
run: |
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
/orgs/runcycles/packages/container/cycles-server/versions \
|| true
# Set the container package to public so unauthenticated pulls work
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
/orgs/runcycles/packages/container/cycles-server \
-f visibility=public \
|| echo "Note: Could not set package visibility. Set it manually in GitHub package settings."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Smoke-test the *published* image, not a rebuild. Catches failure
# modes that unit/integration tests can't see — wrong entry point,
# missing files in the image, startup script typos, multi-arch
# manifest issues.
smoke-test-published:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
timeout-minutes: 8
steps:
- name: Log in to GHCR
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create network and start redis
run: |
docker network create smoke-net
docker run -d --name smoke-redis --network smoke-net --network-alias redis redis:7-alpine
for i in $(seq 1 10); do
if docker exec smoke-redis redis-cli ping >/dev/null 2>&1; then
echo "redis ready"
break
fi
sleep 1
done
- name: Run the published cycles-server image
env:
VERSION: ${{ needs.build-and-push.outputs.version }}
run: >
docker run -d
--name smoke-server
--network smoke-net
-p 7878:7878
-e REDIS_HOST=redis
-e REDIS_PORT=6379
-e REDIS_PASSWORD=
-e ADMIN_API_KEY=smoke-test-admin-key
ghcr.io/runcycles/cycles-server:${VERSION}
- name: Wait for /actuator/health/readiness
run: |
for i in $(seq 1 30); do
code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:7878/actuator/health/readiness || echo "000")
if [ "$code" = "200" ]; then
echo "cycles-server ready after $((i*2))s"
curl -s http://localhost:7878/actuator/health/readiness
echo
exit 0
fi
echo "waiting ($i/30) — status=$code"
sleep 2
done
echo "ERROR: cycles-server did not become ready in 60s"
docker logs smoke-server | tail -50
exit 1
- name: Smoke probe — admin dual-auth allowlist works
run: |
# /v1/reservations is in the admin-dual-auth allowlist (v0.1.25.8)
# and REQUIRED tenant under admin. Missing tenant should return 400
# INVALID_REQUEST with a specific message, not HTML / 500.
body=$(curl -s -H "X-Admin-API-Key: smoke-test-admin-key" http://localhost:7878/v1/reservations)
echo "Body: $body"
echo "$body" | python -c "
import sys, json
d = json.loads(sys.stdin.read())
assert d.get('error') == 'INVALID_REQUEST', f'unexpected: {d}'
assert 'tenant' in d.get('message', '').lower(), f'unexpected message: {d}'
"
- name: Smoke probe — missing API key returns structured 401
run: |
body=$(curl -s http://localhost:7878/v1/reservations)
echo "Body: $body"
echo "$body" | python -c "
import sys, json
d = json.loads(sys.stdin.read())
assert d.get('error') == 'UNAUTHORIZED', f'unexpected: {d}'
"
- name: Capture logs on failure
if: failure()
run: docker logs smoke-server > smoke-server.log 2>&1 || true
- name: Upload logs on failure
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: smoke-test-logs
path: smoke-server.log
retention-days: 14
- name: Tear down
if: always()
run: |
docker rm -f smoke-server smoke-redis || true
docker network rm smoke-net || true