-
Notifications
You must be signed in to change notification settings - Fork 1
378 lines (332 loc) · 13.5 KB
/
Copy pathrelease.yml
File metadata and controls
378 lines (332 loc) · 13.5 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
name: Release
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
packages: write
checks: read
security-events: write
id-token: write
actions: read
env:
REGISTRY: ghcr.io/schwichtgit
COSIGN_YES: 'true'
jobs:
# Gate: verify CI passed and changelog has an entry for this version
validate:
runs-on: ubuntu-latest
outputs:
ci_run_id: ${{ steps.ci.outputs.run_id }}
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract version and detect pre-release
id: version
run: |
VERSION="${GITHUB_REF_NAME#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Wait for CI to complete
id: ci
run: |
SHA="${{ github.sha }}"
TAG_NAME="${{ github.ref_name }}"
REPO="${{ github.repository }}"
echo "Waiting for CI to pass on commit ${SHA}..."
MAX_WAIT=1800 # 30 minutes
POLL_INTERVAL=30
ELAPSED=0
# check_run: given a run ID, verify it has successful container
# builds AND a successful summary job. Prints "pass" on success.
check_run() {
local rid=$1
local conclusion
conclusion=$(gh api "repos/${REPO}/actions/runs/${rid}" --jq '.conclusion')
if [ "$conclusion" != "success" ]; then
return
fi
local build_jobs
build_jobs=$(gh api "repos/${REPO}/actions/runs/${rid}/jobs?per_page=100" \
--jq '[.jobs[] | select(.name | startswith("container-build")) | select(.conclusion == "success")] | length')
if [ "$build_jobs" -eq 0 ]; then
return
fi
local summary
summary=$(gh api "repos/${REPO}/actions/runs/${rid}/jobs?per_page=100" \
--jq '.jobs[] | select(.name == "summary") | .conclusion')
if [ "$summary" = "success" ]; then
echo "pass"
fi
}
# has_in_progress: check if any CI run for this SHA is still running
# (e.g. a re-run). Returns "yes" if so.
has_in_progress() {
local count
count=$(gh api "repos/${REPO}/actions/workflows/ci.yml/runs?head_sha=${SHA}" \
--jq '[.workflow_runs[] | select(.status != "completed")] | length')
if [ "$count" -gt 0 ]; then
echo "yes"
fi
}
RUN_ID=""
while [ "$ELAPSED" -lt "$MAX_WAIT" ]; do
# Fetch all CI runs for this commit (completed or not), newest first.
# Prefer tag-triggered runs over main-push runs.
for rid in $(gh api "repos/${REPO}/actions/workflows/ci.yml/runs?head_sha=${SHA}" \
--jq "[.workflow_runs[] | select(.head_branch == \"${TAG_NAME}\")] | sort_by(.run_started_at) | reverse | .[].id"); do
if [ "$(check_run "$rid")" = "pass" ]; then
RUN_ID="$rid"
break 2
fi
done
# Fallback: accept any run for this SHA
for rid in $(gh api "repos/${REPO}/actions/workflows/ci.yml/runs?head_sha=${SHA}" \
--jq '.workflow_runs | sort_by(.run_started_at) | reverse | .[].id'); do
if [ "$(check_run "$rid")" = "pass" ]; then
RUN_ID="$rid"
echo "::warning::No tag-triggered CI run passed, using run ${rid}"
break 2
fi
done
# If no runs are still in progress, no point waiting further
if [ "$(has_in_progress)" != "yes" ]; then
echo "::error::All CI runs for ${SHA} have completed without passing"
exit 1
fi
echo "CI not ready yet (${ELAPSED}s elapsed), polling in ${POLL_INTERVAL}s..."
sleep "$POLL_INTERVAL"
ELAPSED=$((ELAPSED + POLL_INTERVAL))
done
if [ -z "$RUN_ID" ]; then
echo "::error::CI did not pass within ${MAX_WAIT}s for commit ${SHA}"
exit 1
fi
echo "CI passed (run ${RUN_ID})"
echo "run_id=${RUN_ID}" >> "$GITHUB_OUTPUT"
- name: Validate changelog entry
if: steps.version.outputs.prerelease == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
if ! grep -qF "## [$VERSION]" CHANGELOG.md; then
echo "::error::CHANGELOG.md missing entry for version $VERSION"
echo "Expected a heading like: ## [$VERSION]"
exit 1
fi
echo "Changelog entry found for version $VERSION"
# Merge arch-specific images (built in CI) into multi-arch manifests
merge-manifests:
needs: validate
runs-on: ubuntu-latest
strategy:
matrix:
image:
[
ai-resume-frontend,
ai-resume-api,
ai-resume-memvid,
ai-resume-ingest,
]
steps:
- uses: actions/checkout@v6
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Login to ghcr.io
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download CI digest artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
# Use the validated CI run ID from the validate job (avoids picking
# a docs-only main-push run with skipped container-build jobs).
RUN_ID="${{ needs.validate.outputs.ci_run_id }}"
if [ -z "$RUN_ID" ]; then
echo "::warning::No CI run ID from validate, falling back to tag-based merge"
exit 0
fi
echo "Using validated CI run: ${RUN_ID}"
# Map matrix image name to CI short name
case "${{ matrix.image }}" in
ai-resume-frontend) SHORT=frontend ;;
ai-resume-api) SHORT=api ;;
ai-resume-memvid) SHORT=memvid ;;
ai-resume-ingest) SHORT=ingest ;;
esac
mkdir -p /tmp/digests
for ARCH in amd64 arm64; do
ARTIFACT_NAME="digest-${SHORT}-${ARCH}"
echo "Downloading artifact: ${ARTIFACT_NAME}"
ARTIFACT_ID=$(gh api "repos/${{ github.repository }}/actions/runs/${RUN_ID}/artifacts" \
--jq ".artifacts[] | select(.name == \"${ARTIFACT_NAME}\") | .id")
if [ -n "$ARTIFACT_ID" ]; then
gh api "repos/${{ github.repository }}/actions/artifacts/${ARTIFACT_ID}/zip" \
> "/tmp/digests/${ARTIFACT_NAME}.zip"
cd /tmp/digests && unzip -o "${ARTIFACT_NAME}.zip" -d "${ARTIFACT_NAME}" && cd -
echo "Downloaded: ${ARTIFACT_NAME}"
else
echo "::warning::Artifact ${ARTIFACT_NAME} not found"
fi
done
- name: Extract digests
id: digests
run: |
case "${{ matrix.image }}" in
ai-resume-frontend) SHORT=frontend ;;
ai-resume-api) SHORT=api ;;
ai-resume-memvid) SHORT=memvid ;;
ai-resume-ingest) SHORT=ingest ;;
esac
AMD64_DIGEST=""
ARM64_DIGEST=""
if [ -f "/tmp/digests/digest-${SHORT}-amd64/digest-metadata.json" ]; then
AMD64_DIGEST=$(jq -r .digest "/tmp/digests/digest-${SHORT}-amd64/digest-metadata.json")
echo "amd64 digest: ${AMD64_DIGEST}"
fi
if [ -f "/tmp/digests/digest-${SHORT}-arm64/digest-metadata.json" ]; then
ARM64_DIGEST=$(jq -r .digest "/tmp/digests/digest-${SHORT}-arm64/digest-metadata.json")
echo "arm64 digest: ${ARM64_DIGEST}"
fi
echo "amd64=${AMD64_DIGEST}" >> "$GITHUB_OUTPUT"
echo "arm64=${ARM64_DIGEST}" >> "$GITHUB_OUTPUT"
- name: Merge arch manifests
run: |
chmod +x scripts/publish-ci.sh
DIGEST_FLAGS=""
if [ -n "${{ steps.digests.outputs.amd64 }}" ]; then
DIGEST_FLAGS="$DIGEST_FLAGS --digest-amd64 ${{ steps.digests.outputs.amd64 }}"
fi
if [ -n "${{ steps.digests.outputs.arm64 }}" ]; then
DIGEST_FLAGS="$DIGEST_FLAGS --digest-arm64 ${{ steps.digests.outputs.arm64 }}"
fi
scripts/publish-ci.sh merge $DIGEST_FLAGS "${{ env.REGISTRY }}" "${{ matrix.image }}" "${{ github.ref_name }}"
- name: Sign manifest list
run: |
cosign sign "${{ env.REGISTRY }}/${{ matrix.image }}:${{ github.ref_name }}"
# Verify all signatures before tag promotion
verify-signatures:
needs: merge-manifests
runs-on: ubuntu-latest
strategy:
matrix:
image:
[
ai-resume-frontend,
ai-resume-api,
ai-resume-memvid,
ai-resume-ingest,
]
steps:
- uses: actions/checkout@v6
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Login to ghcr.io
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify arch image signatures (CI-signed)
run: |
for ARCH in amd64 arm64; do
echo "Verifying ${ARCH} image..."
cosign verify \
--certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/ci.yml@refs/heads/main" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
"${{ env.REGISTRY }}/${{ matrix.image }}:${{ github.ref_name }}.${ARCH}" || \
cosign verify \
--certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/ci.yml@${{ github.ref }}" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
"${{ env.REGISTRY }}/${{ matrix.image }}:${{ github.ref_name }}.${ARCH}"
done
- name: Verify manifest list signature (release-signed)
run: |
cosign verify \
--certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/release.yml@${{ github.ref }}" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
"${{ env.REGISTRY }}/${{ matrix.image }}:${{ github.ref_name }}"
# Apply semver tag family (major, major.minor, latest) to all images
publish-tags:
needs: verify-signatures
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install skopeo
run: |
sudo apt-get update
sudo apt-get install -y skopeo
- name: Login to ghcr.io (skopeo)
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | skopeo login ghcr.io \
-u "${{ github.actor }}" --password-stdin
- name: Apply semver tag family
run: |
chmod +x scripts/publish-ci.sh
IMAGES=(ai-resume-frontend ai-resume-api ai-resume-memvid ai-resume-ingest)
for IMG in "${IMAGES[@]}"; do
scripts/publish-ci.sh tag-family "${{ env.REGISTRY }}" "$IMG" "${{ github.ref_name }}"
done
# Create GitHub Release with auto-generated notes
create-release:
needs: publish-tags
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Generate release notes with container images
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${GITHUB_REF_NAME#v}"
PRERELEASE_FLAG=""
if [[ "$VERSION" == *-* ]]; then
PRERELEASE_FLAG="--prerelease"
fi
# Generate auto-notes into a temp file
gh api "repos/${{ github.repository }}/releases/generate-notes" \
-f tag_name="$GITHUB_REF_NAME" \
--jq '.body' > /tmp/release-notes.md
# Append container image references
REG="${{ env.REGISTRY }}"
REPO="${{ github.repository }}"
TAG="${GITHUB_REF_NAME}"
{
echo ""
echo "## Container Images"
echo ""
echo "All images are multi-arch (linux/amd64, linux/arm64) and signed with cosign."
echo ""
echo "| Service | Image |"
echo "|---------|-------|"
echo "| Frontend | \`${REG}/ai-resume-frontend:${TAG}\` |"
echo "| API | \`${REG}/ai-resume-api:${TAG}\` |"
echo "| Memvid | \`${REG}/ai-resume-memvid:${TAG}\` |"
echo "| Ingest | \`${REG}/ai-resume-ingest:${TAG}\` |"
echo ""
echo '```bash'
echo "podman pull ${REG}/ai-resume-frontend:${TAG}"
echo "podman pull ${REG}/ai-resume-api:${TAG}"
echo "podman pull ${REG}/ai-resume-memvid:${TAG}"
echo "podman pull ${REG}/ai-resume-ingest:${TAG}"
echo ""
echo "# Verify signatures"
echo "cosign verify \\"
echo " --certificate-identity \"https://github.com/${REPO}/.github/workflows/release.yml@refs/tags/${TAG}\" \\"
echo " --certificate-oidc-issuer \"https://token.actions.githubusercontent.com\" \\"
echo " ${REG}/ai-resume-frontend:${TAG}"
echo '```'
} >> /tmp/release-notes.md
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file /tmp/release-notes.md \
$PRERELEASE_FLAG