-
Notifications
You must be signed in to change notification settings - Fork 0
461 lines (417 loc) · 19.9 KB
/
Copy pathrelease.yml
File metadata and controls
461 lines (417 loc) · 19.9 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
name: Release
on:
workflow_dispatch:
inputs:
source_ref:
description: Source ref to release, such as refs/heads/release or
refs/tags/v0.2.0.
required: false
type: string
source_sha:
description: Source commit SHA to release. Defaults to the selected ref SHA.
required: false
type: string
publish_npm:
description: Publish npm packages.
required: true
type: boolean
default: false
publish_crates:
description: Publish Rust crates.
required: true
type: boolean
default: false
publish_docker:
description: Publish Docker image.
required: true
type: boolean
default: false
permissions:
contents: read
concurrency:
group: release-${{ inputs.source_sha || inputs.source_ref || github.ref }}
cancel-in-progress: false
env:
RELEASE_BRANCH: release
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
release-plan:
runs-on: ubuntu-latest
outputs:
source_event: ${{ steps.plan.outputs.source_event }}
source_ref: ${{ steps.plan.outputs.source_ref }}
source_ref_name: ${{ steps.plan.outputs.source_ref_name }}
source_sha: ${{ steps.plan.outputs.source_sha }}
version: ${{ steps.plan.outputs.version }}
expected_tag: ${{ steps.plan.outputs.expected_tag }}
expected_tag_status: ${{ steps.plan.outputs.expected_tag_status }}
expected_tag_target: ${{ steps.plan.outputs.expected_tag_target }}
expected_tag_policy: ${{ steps.plan.outputs.expected_tag_policy }}
can_publish: ${{ steps.plan.outputs.can_publish }}
publish_npm: ${{ steps.plan.outputs.publish_npm }}
publish_crates: ${{ steps.plan.outputs.publish_crates }}
publish_docker: ${{ steps.plan.outputs.publish_docker }}
local_run: ${{ steps.plan.outputs.local_run }}
cache_scope: ${{ steps.plan.outputs.cache_scope }}
release_branch: ${{ steps.plan.outputs.release_branch }}
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ inputs.source_sha || inputs.source_ref || github.sha }}
fetch-depth: 0
- name: Setup mise and pnpm dependencies
uses: ./.github/actions/setup-mise-pnpm
with:
cache-mode: read-write
- name: Resolve release plan
id: plan
env:
PUBLISH_NPM: ${{ inputs.publish_npm }}
PUBLISH_CRATES: ${{ inputs.publish_crates }}
PUBLISH_DOCKER: ${{ inputs.publish_docker }}
SOURCE_REF: ${{ inputs.source_ref || '' }}
SOURCE_SHA: ${{ inputs.source_sha || '' }}
run: >-
mise exec --command "node scripts/release-cli.ts workflow
release-plan --format=github-output --source-ref=${SOURCE_REF}
--source-sha=${SOURCE_SHA} --publish-npm=${PUBLISH_NPM}
--publish-crates=${PUBLISH_CRATES}
--publish-docker=${PUBLISH_DOCKER}"
- name: Validate release source
if: steps.plan.outputs.can_publish == 'true'
run: >-
mise exec --command "node scripts/release-cli.ts workflow
validate-release-ref --kind=release --mode=publish --ref=${{
steps.plan.outputs.source_ref }} --ref-name=${{
steps.plan.outputs.source_ref_name }} --sha=${{
steps.plan.outputs.source_sha }}"
- name: Upload release plan report
uses: actions/upload-artifact@v7
with:
name: release-plan-report
path: temp/release/release-plan.json
npm-release:
if: needs.release-plan.outputs.can_publish == 'true' &&
needs.release-plan.outputs.publish_npm == 'true'
needs: release-plan
runs-on: ubuntu-latest
environment:
name: npm-release
permissions:
contents: read
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ needs.release-plan.outputs.source_sha }}
- name: Setup mise and pnpm dependencies
uses: ./.github/actions/setup-mise-pnpm
with:
cache-mode: read-only
- name: Restore Turbo npm release cache
id: turbo-npm-release-cache
uses: actions/cache/restore@v5
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ needs.release-plan.outputs.cache_scope }}-release-npm-${{ hashFiles('pnpm-lock.yaml', 'turbo.json') }}-${{ needs.release-plan.outputs.source_sha }}
restore-keys: |
turbo-${{ runner.os }}-${{ needs.release-plan.outputs.cache_scope }}-release-npm-${{ hashFiles('pnpm-lock.yaml', 'turbo.json') }}-
- name: Build TypeScript SDK packages for npm release
run: mise exec --command "pnpm build:sdks"
- name: Save Turbo npm release cache
if: steps.turbo-npm-release-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: .turbo
key: ${{ steps.turbo-npm-release-cache.outputs.cache-primary-key }}
- name: Publish npm packages
env:
LOCAL_RUN: ${{ needs.release-plan.outputs.local_run }}
run: |
set -euo pipefail
if [[ "${LOCAL_RUN}" == "true" ]]; then
mise exec --command "node scripts/release-cli.ts npm publish --mode=dry-run --report=temp/release/npm/dry-run-report.json"
else
mise exec --command "node scripts/release-cli.ts npm publish --mode=publish --provenance --report=temp/release/npm/publish-report.json"
fi
- name: Upload npm release artifacts
uses: actions/upload-artifact@v7
with:
name: npm-publish-report
path: temp/release/npm
crates-release:
if: needs.release-plan.outputs.can_publish == 'true' &&
needs.release-plan.outputs.publish_crates == 'true'
needs: release-plan
runs-on: ubuntu-latest
environment:
name: crates-io-release
permissions:
contents: read
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ needs.release-plan.outputs.source_sha }}
fetch-depth: 0
- name: Setup mise and pnpm dependencies
uses: ./.github/actions/setup-mise-pnpm
with:
cache-mode: read-only
- name: Restore Rust debug build cache
uses: ./.github/actions/setup-rust-cache
with:
shared-key: securitydept-rust-${{ runner.os }}-${{
needs.release-plan.outputs.cache_scope }}-debug
cache-mode: read-only
- name: Run crates package gate
run: >-
mise exec --command "node scripts/release-cli.ts crates
publish --mode=package
--report=temp/release/crates/package-report.json"
- name: Exchange GitHub OIDC token for crates.io publish token
if: needs.release-plan.outputs.local_run != 'true'
id: crates-io-auth
uses: rust-lang/crates-io-auth-action@v1
- name: Publish Rust crates
if: needs.release-plan.outputs.local_run != 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
run: >-
mise exec --command "node scripts/release-cli.ts crates
publish --mode=publish
--report=temp/release/crates/publish-report.json"
- name: Record local crates publish dry run
if: needs.release-plan.outputs.local_run == 'true'
shell: bash
run: |
set -euo pipefail
cp temp/release/crates/package-report.json temp/release/crates/publish-report.json
- name: Upload crates release artifacts
uses: actions/upload-artifact@v7
with:
name: crates-publish-report
path: temp/release/crates
docker-release:
if: needs.release-plan.outputs.can_publish == 'true' &&
needs.release-plan.outputs.publish_docker == 'true'
needs: release-plan
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ needs.release-plan.outputs.source_sha }}
- name: Setup mise and pnpm dependencies
uses: ./.github/actions/setup-mise-pnpm
with:
cache-mode: read-only
- name: Restore Turbo web UI release cache
id: turbo-webui-release-cache
uses: actions/cache/restore@v5
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ needs.release-plan.outputs.cache_scope }}-release-webui-${{ hashFiles('pnpm-lock.yaml', 'turbo.json') }}-${{ needs.release-plan.outputs.source_sha }}
restore-keys: |
turbo-${{ runner.os }}-${{ needs.release-plan.outputs.cache_scope }}-release-webui-${{ hashFiles('pnpm-lock.yaml', 'turbo.json') }}-
- name: Restore Rust release build cache
uses: ./.github/actions/setup-rust-cache
with:
shared-key: securitydept-rust-${{ runner.os }}-${{
needs.release-plan.outputs.cache_scope }}-release
cache-mode: read-write
- name: Build runtime binaries
run: |
mise exec --command "cargo build --release --manifest-path apps/server/Cargo.toml --bin securitydept-server"
mise exec --command "cargo build --release --manifest-path apps/cli/Cargo.toml --bin securitydept-cli"
- name: Build web UI assets
run: mise exec --command "pnpm stage:webui"
- name: Save Turbo web UI release cache
if: steps.turbo-webui-release-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: .turbo
key: ${{ steps.turbo-webui-release-cache.outputs.cache-primary-key }}
- name: Stage runtime artifacts
shell: bash
run: |
set -euo pipefail
rm -rf release-runtime
mkdir -p release-runtime/bin release-runtime/webui temp/release/docker
cp target/release/securitydept-server release-runtime/bin/securitydept-server
cp target/release/securitydept-cli release-runtime/bin/securitydept-cli
cp -R webui/. release-runtime/webui/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
if: needs.release-plan.outputs.local_run != 'true'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve Docker tags and labels
id: docker_plan
shell: bash
env:
SOURCE_REF: ${{ needs.release-plan.outputs.source_ref }}
SOURCE_SHA: ${{ needs.release-plan.outputs.source_sha }}
EXPECTED_TAG: ${{ needs.release-plan.outputs.expected_tag }}
run: |
set -euo pipefail
image_ref="$(printf '%s' "${REGISTRY}/${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')"
docker_ref="${SOURCE_REF}"
if [[ "${docker_ref}" == "refs/heads/${RELEASE_BRANCH}" ]]; then
docker_ref="refs/tags/${EXPECTED_TAG}"
fi
mise exec --command "node scripts/release-cli.ts docker publish --format=github-output --ref=${docker_ref} --sha=${SOURCE_SHA} --revision=${SOURCE_SHA} --image=${image_ref} --source-url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
mise exec --command "node scripts/release-cli.ts docker publish --format=json --ref=${docker_ref} --sha=${SOURCE_SHA} --revision=${SOURCE_SHA} --image=${image_ref} --source-url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" > temp/release/docker/publish-report.json
- name: Build and push runtime Docker image
if: needs.release-plan.outputs.local_run != 'true'
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.runtime
platforms: linux/amd64
push: true
tags: ${{ steps.docker_plan.outputs.tags }}
labels: ${{ steps.docker_plan.outputs.labels }}
cache-from: type=gha,scope=docker-runtime-amd64
cache-to: type=gha,mode=max,scope=docker-runtime-amd64
- name: Build runtime Docker image locally
if: needs.release-plan.outputs.local_run == 'true'
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile.runtime
platforms: linux/amd64
push: false
load: true
tags: ${{ steps.docker_plan.outputs.tags }}
labels: ${{ steps.docker_plan.outputs.labels }}
- name: Upload Docker release artifacts
uses: actions/upload-artifact@v7
with:
name: docker-publish-report
path: |
temp/release/docker
release-runtime
release-report:
if: always()
needs:
- release-plan
- npm-release
- crates-release
- docker-release
runs-on: ubuntu-latest
steps:
- name: Write release workflow report
shell: bash
env:
SOURCE_REF: ${{ needs.release-plan.outputs.source_ref }}
SOURCE_REF_NAME: ${{ needs.release-plan.outputs.source_ref_name }}
SOURCE_SHA: ${{ needs.release-plan.outputs.source_sha }}
VERSION: ${{ needs.release-plan.outputs.version }}
EXPECTED_TAG: ${{ needs.release-plan.outputs.expected_tag }}
EXPECTED_TAG_STATUS: ${{ needs.release-plan.outputs.expected_tag_status }}
EXPECTED_TAG_TARGET: ${{ needs.release-plan.outputs.expected_tag_target }}
EXPECTED_TAG_POLICY: ${{ needs.release-plan.outputs.expected_tag_policy }}
CAN_PUBLISH: ${{ needs.release-plan.outputs.can_publish }}
PUBLISH_NPM: ${{ needs.release-plan.outputs.publish_npm }}
PUBLISH_CRATES: ${{ needs.release-plan.outputs.publish_crates }}
PUBLISH_DOCKER: ${{ needs.release-plan.outputs.publish_docker }}
LOCAL_RUN: ${{ needs.release-plan.outputs.local_run }}
NPM_RESULT: ${{ needs.npm-release.result }}
CRATES_RESULT: ${{ needs.crates-release.result }}
DOCKER_RESULT: ${{ needs.docker-release.result }}
run: |
set -euo pipefail
mkdir -p temp/release
cat > temp/release/release-workflow-report.json <<EOF
{
"schemaVersion": 1,
"createdAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"sourceRef": "${SOURCE_REF}",
"sourceRefName": "${SOURCE_REF_NAME}",
"sourceSha": "${SOURCE_SHA}",
"version": "${VERSION}",
"expectedTag": "${EXPECTED_TAG}",
"expectedTagStatus": "${EXPECTED_TAG_STATUS}",
"expectedTagTarget": "${EXPECTED_TAG_TARGET}",
"expectedTagPolicy": "${EXPECTED_TAG_POLICY}",
"canPublish": ${CAN_PUBLISH:-false},
"publishNpm": ${PUBLISH_NPM:-false},
"publishCrates": ${PUBLISH_CRATES:-false},
"publishDocker": ${PUBLISH_DOCKER:-false},
"localRun": ${LOCAL_RUN:-false},
"jobs": {
"npmRelease": "${NPM_RESULT}",
"cratesRelease": "${CRATES_RESULT}",
"dockerRelease": "${DOCKER_RESULT}"
}
}
EOF
- name: Upload release workflow report
uses: actions/upload-artifact@v7
with:
name: release-workflow-report
path: temp/release/release-workflow-report.json
- name: Enforce release job results
if: needs.release-plan.outputs.can_publish == 'true'
shell: bash
env:
PUBLISH_NPM: ${{ needs.release-plan.outputs.publish_npm }}
PUBLISH_CRATES: ${{ needs.release-plan.outputs.publish_crates }}
PUBLISH_DOCKER: ${{ needs.release-plan.outputs.publish_docker }}
NPM_RESULT: ${{ needs.npm-release.result }}
CRATES_RESULT: ${{ needs.crates-release.result }}
DOCKER_RESULT: ${{ needs.docker-release.result }}
run: |
set -euo pipefail
if [[ "${PUBLISH_NPM}" == "true" && "${NPM_RESULT}" != "success" ]]; then
exit 1
fi
if [[ "${PUBLISH_CRATES}" == "true" && "${CRATES_RESULT}" != "success" ]]; then
exit 1
fi
if [[ "${PUBLISH_DOCKER}" == "true" && "${DOCKER_RESULT}" != "success" ]]; then
exit 1
fi
release-tag:
if: >-
needs.release-plan.outputs.can_publish == 'true' &&
needs.release-plan.outputs.local_run != 'true' &&
needs.release-plan.outputs.source_ref == 'refs/heads/release' &&
(needs.release-plan.outputs.publish_npm == 'true' ||
needs.release-plan.outputs.publish_crates == 'true' ||
needs.release-plan.outputs.publish_docker == 'true')
needs:
- release-plan
- release-report
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout source
uses: actions/checkout@v6
with:
ref: ${{ needs.release-plan.outputs.source_sha }}
fetch-depth: 0
- name: Setup mise and pnpm dependencies
uses: ./.github/actions/setup-mise-pnpm
with:
cache-mode: read-only
- name: Create or verify release tag
run: >-
mise exec --command "node scripts/release-cli.ts workflow
ensure-release-tag --ref=${{
needs.release-plan.outputs.source_ref }} --ref-name=${{
needs.release-plan.outputs.source_ref_name }} --sha=${{
needs.release-plan.outputs.source_sha }} --push"