-
Notifications
You must be signed in to change notification settings - Fork 52
379 lines (334 loc) · 11.2 KB
/
Copy pathstable-release.yml
File metadata and controls
379 lines (334 loc) · 11.2 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
---
name: Stable Release
"on":
workflow_dispatch:
inputs:
release_tag:
description: Stable semver tag to create, such as v0.10.0
required: true
type: string
# Stable releases are intentionally immutable. Re-running with an existing tag
# or release fails instead of replacing published assets.
concurrency:
group: ${{ github.workflow }}-${{ inputs.release_tag }}
cancel-in-progress: false
permissions:
contents: read
env:
DATAFILES_ARCHIVE: gomud-ALL-datafiles.zip
CHECKSUMS_FILE: SHA256SUMS.txt
jobs:
validate-release:
name: Validate Stable Release Request
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: read
env:
RELEASE_TAG: ${{ inputs.release_tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
binary_version: ${{ steps.meta.outputs.binary_version }}
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- name: Validate stable release request
id: meta
run: |
set -euo pipefail
if [ "${GITHUB_REF}" != "refs/heads/master" ]; then
echo "Stable releases must be run from the master branch." >&2
exit 1
fi
semver_re='^v(0|[1-9][0-9]*)\.'
semver_re="${semver_re}(0|[1-9][0-9]*)\."
semver_re="${semver_re}(0|[1-9][0-9]*)$"
if ! printf '%s\n' "$RELEASE_TAG" | grep -Eq "$semver_re"; then
echo "release_tag must be a stable semver tag like v0.10.0" >&2
exit 1
fi
if gh api \
"repos/${GITHUB_REPOSITORY}/git/ref/tags/${RELEASE_TAG}" \
>/dev/null 2>&1; then
echo "Tag ${RELEASE_TAG} already exists; stable releases are" \
"immutable." >&2
exit 1
fi
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Release ${RELEASE_TAG} already exists; stable releases are" \
"immutable." >&2
exit 1
fi
binary_version="$(
awk -F'"' '/^const VERSION = "/ { print $2; exit }' main.go
)"
if [ -z "$binary_version" ]; then
echo "Could not determine binary version from main.go" >&2
exit 1
fi
echo "binary_version=${binary_version}" >> "$GITHUB_OUTPUT"
test:
name: Validate Release Source
runs-on: ubuntu-24.04
timeout-minutes: 30
needs: validate-release
permissions:
contents: read
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/go-checks
build:
name: Build Release Binary (${{ matrix.label }})
runs-on: ubuntu-24.04
timeout-minutes: 20
needs:
- validate-release
- test
strategy:
fail-fast: false
matrix:
include:
- label: Linux amd64
asset: gomud-linux_x64
- label: Linux arm64
asset: gomud-linux_arm64
- label: Linux arm/v7
asset: gomud-linux_armv7
- label: Windows amd64
asset: gomud-windows_x64.exe
- label: Windows arm64
asset: gomud-windows_arm64.exe
- label: macOS amd64
asset: gomud-darwin_x64
- label: macOS arm64
asset: gomud-darwin_arm64
permissions:
contents: read
env:
BINARY_VERSION: ${{ needs.validate-release.outputs.binary_version }}
RELEASE_TARGET_ASSET: ${{ matrix.asset }}
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- uses: ./.github/actions/setup-go
- name: Build release binary
run: .github/scripts/build-release-binaries.sh
- name: Upload release binary
# actions/upload-artifact v7.0.1
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: release-binary-${{ matrix.asset }}
path: dist/${{ matrix.asset }}
if-no-files-found: error
stage-release:
name: Stage Stable Release
runs-on: ubuntu-24.04
timeout-minutes: 30
needs:
- validate-release
- build
environment: stable-release
permissions:
contents: write
id-token: write
attestations: write
outputs:
release_id: ${{ steps.draft.outputs.release_id }}
env:
RELEASE_TAG: ${{ inputs.release_tag }}
RELEASE_TITLE: ${{ inputs.release_tag }}
BINARY_VERSION: ${{ needs.validate-release.outputs.binary_version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- name: Recheck stable release immutability
# The first check catches bad manual inputs early. This second check
# runs after environment approval in case someone created the tag or
# release while the workflow was waiting.
run: |
set -euo pipefail
if gh api \
"repos/${GITHUB_REPOSITORY}/git/ref/tags/${RELEASE_TAG}" \
>/dev/null 2>&1; then
echo "Tag ${RELEASE_TAG} already exists; stable releases are" \
"immutable." >&2
exit 1
fi
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Release ${RELEASE_TAG} already exists; stable releases are" \
"immutable." >&2
exit 1
fi
- name: Download release binaries
# actions/download-artifact v8.0.1
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
pattern: release-binary-*
path: bin/
merge-multiple: true
- name: Assemble release assets
run: .github/scripts/assemble-release-assets.sh
- name: Write release notes
env:
RELEASE_KIND: stable
RELEASE_NOTES_FILE: release-notes.md
run: .github/scripts/release-notes.sh
- name: Resolve attestation paths
id: release-assets
# Attest binaries and checksums. The datafiles zip is covered by the
# checksum file because it is assembled inside this workflow.
run: |
{
echo 'attestation_paths<<EOF'
.github/scripts/release-assets.sh attestation-paths
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Attest release assets
# actions/attest-build-provenance v4.1.0
# yamllint disable-line rule:line-length
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32
with:
subject-path: ${{ steps.release-assets.outputs.attestation_paths }}
- name: Create stable draft release
id: draft
# Draft first so a failed upload does not expose a partial release.
run: |
set -euo pipefail
release_id="$(
gh api \
-X POST \
"repos/${GITHUB_REPOSITORY}/releases" \
-f "tag_name=${RELEASE_TAG}" \
-f "target_commitish=${GITHUB_SHA}" \
-f "name=${RELEASE_TITLE}" \
-f "body=Stable release assets are uploading." \
-f "make_latest=true" \
-F draft=true \
-F prerelease=false \
--jq '.id'
)"
echo "release_id=${release_id}" >> "$GITHUB_OUTPUT"
- name: Upload stable release assets
run: |
set -euo pipefail
mapfile -t assets < <(
.github/scripts/release-assets.sh upload-paths
)
gh release upload "$RELEASE_TAG" "${assets[@]}"
- name: Attach stable release notes
run: |
set -euo pipefail
gh release edit "$RELEASE_TAG" \
--notes-file release-notes.md \
--title "$RELEASE_TITLE" \
--latest
docker-image:
name: Publish Stable Docker Image
needs:
- validate-release
- stage-release
uses: ./.github/workflows/docker-package.yml
permissions:
contents: read
packages: write
attestations: write
id-token: write
with:
release_tag: ${{ inputs.release_tag }}
publish:
name: Publish Stable Release
runs-on: ubuntu-24.04
timeout-minutes: 5
needs:
- stage-release
- docker-image
permissions:
contents: write
env:
RELEASE_ID: ${{ needs.stage-release.outputs.release_id }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Publish stable release
run: |
set -euo pipefail
gh api \
-X PATCH \
"repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
-F draft=false \
-F prerelease=false
cleanup-failed-draft:
name: Cleanup Failed Stable Draft
runs-on: ubuntu-24.04
timeout-minutes: 5
needs:
- stage-release
- docker-image
- publish
if: >-
${{
always() &&
(
needs.stage-release.result == 'failure' ||
needs.docker-image.result == 'failure' ||
needs.publish.result == 'failure'
)
}}
permissions:
contents: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ needs.stage-release.outputs.release_id }}
RELEASE_TAG: ${{ inputs.release_tag }}
steps:
- name: Delete unpublished stable draft
run: |
set -euo pipefail
# Only delete a draft whose ID came from this run. Looking it up by
# tag can delete a draft created while this run waited for approval.
if [ -z "$RELEASE_ID" ]; then
echo "No draft release ID was created by this workflow run."
exit 0
fi
release_data="$(
gh api "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
--jq '[.id, .tag_name, .draft, .target_commitish] | @tsv' \
2>/dev/null || true
)"
if [ -z "$release_data" ]; then
echo "Draft release ${RELEASE_ID} was not found."
exit 0
fi
IFS=$'\t' read -r release_id tag_name draft target_commitish \
<<<"$release_data"
if [ "$tag_name" != "$RELEASE_TAG" ] ||
[ "$draft" != "true" ] ||
[ "$target_commitish" != "$GITHUB_SHA" ]; then
echo "Release ${RELEASE_TAG} is not this run's draft; leaving it."
exit 0
fi
gh api \
-X DELETE \
"repos/${GITHUB_REPOSITORY}/releases/${release_id}"
tag_sha="$(
gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${RELEASE_TAG}" \
--jq '.object.sha' \
2>/dev/null || true
)"
if [ "$tag_sha" = "$GITHUB_SHA" ]; then
gh api \
-X DELETE \
"repos/${GITHUB_REPOSITORY}/git/refs/tags/${RELEASE_TAG}"
elif [ -n "$tag_sha" ]; then
echo "Tag ${RELEASE_TAG} does not point at this run; leaving it."
fi