Repository navigation
391 lines (355 loc) · 14.7 KB
/
Copy pathrelease.yml
File metadata and controls
391 lines (355 loc) · 14.7 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
name: release
on:
workflow_dispatch:
inputs:
version:
description: Canonical Go module version without the v prefix
required: true
type: string
commit_sha:
description: Full 40-character lowercase SHA of the current main commit
required: true
type: string
batch_id:
description: '1-64 characters; start with a letter or digit; use only letters, digits, ., _, or -'
required: true
type: string
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: read
env:
MODULE_PATH: github.com/QoderAI/qoder-cloud-agents-sdk-go
PROXY_MODULE_PATH: github.com/!qoder!a!i/qoder-cloud-agents-sdk-go
jobs:
preflight:
name: preflight
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Validate dispatch inputs
shell: bash
env:
RELEASE_VERSION: ${{ inputs.version }}
COMMIT_SHA: ${{ inputs.commit_sha }}
BATCH_ID: ${{ inputs.batch_id }}
run: |
set -euo pipefail
if [[ "$GITHUB_REF" != refs/heads/main || "$GITHUB_WORKFLOW_REF" != *@refs/heads/main ]]; then
echo "Release workflow must be dispatched from the main workflow ref." >&2
exit 1
fi
if [[ ! "$COMMIT_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "commit_sha must be a full 40-character lowercase commit SHA" >&2
exit 1
fi
if [[ ! "$BATCH_ID" =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]]; then
echo "batch_id must be 1-64 safe audit-token characters" >&2
exit 1
fi
semver_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'
if [[ ! "$RELEASE_VERSION" =~ $semver_re ]]; then
echo "version must be canonical Go semver without a v prefix or build metadata" >&2
exit 1
fi
if [[ "$RELEASE_VERSION" == *-* ]]; then
prerelease="${RELEASE_VERSION#*-}"
IFS=. read -ra identifiers <<< "$prerelease"
for identifier in "${identifiers[@]}"; do
if [[ "$identifier" =~ ^[0-9]+$ && "$identifier" != "0" && "$identifier" == 0* ]]; then
echo "version has a numeric prerelease identifier with a leading zero: $identifier" >&2
exit 1
fi
done
fi
- name: Check out the approved commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ inputs.commit_sha }}
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version: "1.26.x"
cache: true
- name: Validate main, module version, tag, and proxy state
shell: bash
env:
RELEASE_VERSION: ${{ inputs.version }}
COMMIT_SHA: ${{ inputs.commit_sha }}
BATCH_ID: ${{ inputs.batch_id }}
run: |
set -euo pipefail
git fetch --force --prune origin \
'+refs/heads/main:refs/remotes/origin/main' \
'+refs/tags/*:refs/tags/*'
checked_out_sha=$(git rev-parse HEAD)
main_sha=$(git rev-parse refs/remotes/origin/main)
tag="v${RELEASE_VERSION}"
tag_sha=$(git rev-parse -q --verify "refs/tags/$tag^{commit}" || true)
if [[ "$checked_out_sha" != "$COMMIT_SHA" ]]; then
echo "Checked out $checked_out_sha instead of requested $COMMIT_SHA" >&2
exit 1
fi
if [[ "$main_sha" != "$COMMIT_SHA" && "$tag_sha" != "$COMMIT_SHA" ]]; then
echo "commit_sha $COMMIT_SHA is not current origin/main $main_sha and has no matching release tag" >&2
exit 1
fi
VERSION="$RELEASE_VERSION" make check-version
module=$(go list -m -f '{{.Path}}')
if [[ "$module" != "$MODULE_PATH" ]]; then
echo "Workflow module $MODULE_PATH does not match go.mod module $module" >&2
exit 1
fi
tag="v${RELEASE_VERSION}"
tag_exists=false
if git show-ref --verify --quiet "refs/tags/$tag"; then
tag_exists=true
if [[ "$(git cat-file -t "refs/tags/$tag")" != tag ]]; then
echo "Remote tag $tag must be annotated." >&2
exit 1
fi
tag_sha=$(git rev-list -n 1 "refs/tags/$tag")
if [[ "$tag_sha" != "$COMMIT_SHA" ]]; then
echo "Remote tag $tag already points to $tag_sha" >&2
exit 1
fi
tag_message=$(git for-each-ref --format='%(contents)' "refs/tags/$tag")
if [[ "$tag_message" != "Release $tag (batch_id: $BATCH_ID)" ]]; then
echo "Remote tag $tag does not have the expected release annotation." >&2
exit 1
fi
fi
proxy_tag=$(python3 -c 'import sys; print("".join("!" + c.lower() if c.isupper() else c for c in sys.argv[1]))' "$tag")
proxy_response="$RUNNER_TEMP/go-proxy-version"
# Do not fetch a missing tag from origin and seed a 30-minute negative cache.
proxy_url="https://proxy.golang.org/cached-only/${PROXY_MODULE_PATH}/@v/${proxy_tag}.info"
if ! proxy_status=$(curl --connect-timeout 10 --max-time 30 --silent --show-error --output "$proxy_response" --write-out '%{http_code}' "$proxy_url"); then
echo "Failed to query the public Go proxy" >&2
exit 1
fi
case "$proxy_status" in
200)
if [[ "$tag_exists" != true ]]; then
echo "Public Go proxy already has $tag but the remote tag is absent" >&2
exit 1
fi
;;
404|410)
;;
*)
echo "Public Go proxy returned HTTP $proxy_status" >&2
exit 1
;;
esac
- name: Validate and preview release notes
env:
RELEASE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
python3 .github/scripts/release_notes.py extract \
--version "$RELEASE_VERSION" --output "$RUNNER_TEMP/release-notes.md"
echo "## Changelog for v$RELEASE_VERSION" >> "$GITHUB_STEP_SUMMARY"
cat "$RUNNER_TEMP/release-notes.md" >> "$GITHUB_STEP_SUMMARY"
- name: Lint
run: make lint
- name: Build
run: make build
- name: Test
run: make test
- name: Check generated documentation
run: make docs-check
- name: Build examples
run: go build ./examples/...
publish:
name: publish tag
needs: preflight
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
steps:
- name: Check out the approved commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ inputs.commit_sha }}
fetch-depth: 0
- name: Revalidate main and publish tag
shell: bash
env:
RELEASE_VERSION: ${{ inputs.version }}
COMMIT_SHA: ${{ inputs.commit_sha }}
BATCH_ID: ${{ inputs.batch_id }}
run: |
set -euo pipefail
git fetch --force --prune origin \
'+refs/heads/main:refs/remotes/origin/main' \
'+refs/tags/*:refs/tags/*'
checked_out_sha=$(git rev-parse HEAD)
main_sha=$(git rev-parse refs/remotes/origin/main)
tag="v${RELEASE_VERSION}"
tag_sha=$(git rev-parse -q --verify "refs/tags/$tag^{commit}" || true)
if [[ "$checked_out_sha" != "$COMMIT_SHA" ]]; then
echo "Checked out $checked_out_sha instead of requested $COMMIT_SHA" >&2
exit 1
fi
if [[ "$main_sha" != "$COMMIT_SHA" && "$tag_sha" != "$COMMIT_SHA" ]]; then
echo "origin/main moved to $main_sha before the release tag was created; dispatch a new release" >&2
exit 1
fi
tag_exists=false
if git show-ref --verify --quiet "refs/tags/$tag"; then
tag_exists=true
if [[ "$(git cat-file -t "refs/tags/$tag")" != tag ]]; then
echo "Remote tag $tag must be annotated." >&2
exit 1
fi
tag_sha=$(git rev-list -n 1 "refs/tags/$tag")
if [[ "$tag_sha" != "$COMMIT_SHA" ]]; then
echo "Remote tag $tag already points to $tag_sha" >&2
exit 1
fi
tag_message=$(git for-each-ref --format='%(contents)' "refs/tags/$tag")
if [[ "$tag_message" != "Release $tag (batch_id: $BATCH_ID)" ]]; then
echo "Remote tag $tag does not have the expected release annotation." >&2
exit 1
fi
fi
proxy_tag=$(python3 -c 'import sys; print("".join("!" + c.lower() if c.isupper() else c for c in sys.argv[1]))' "$tag")
# Check for an existing publication without fetching an unpublished tag.
proxy_url="https://proxy.golang.org/cached-only/${PROXY_MODULE_PATH}/@v/${proxy_tag}.info"
proxy_status=$(curl --connect-timeout 10 --max-time 30 --silent --show-error --output /dev/null --write-out '%{http_code}' "$proxy_url")
if [[ "$proxy_status" == 200 && "$tag_exists" != true ]]; then
echo "Public Go proxy already has $tag but the remote tag is absent." >&2
exit 1
fi
if [[ "$proxy_status" != 200 && "$proxy_status" != 404 && "$proxy_status" != 410 ]]; then
echo "Public Go proxy returned HTTP $proxy_status." >&2
exit 1
fi
if [[ "$tag_exists" == true ]]; then
echo "Remote tag $tag already points to $COMMIT_SHA; reusing it"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag --annotate "$tag" "$COMMIT_SHA" \
--message "Release $tag (batch_id: $BATCH_ID)"
git push --atomic --force-with-lease="refs/heads/main:$COMMIT_SHA" origin \
"${COMMIT_SHA}:refs/heads/main" "refs/tags/$tag"
verify:
name: verify public module
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: read
steps:
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version: "1.26.x"
cache: false
- name: Wait for the public Go proxy
shell: bash
env:
RELEASE_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
tag="v${RELEASE_VERSION}"
proxy_tag=$(python3 -c 'import sys; print("".join("!" + c.lower() if c.isupper() else c for c in sys.argv[1]))' "$tag")
proxy_url="https://proxy.golang.org/${PROXY_MODULE_PATH}/@v/${proxy_tag}.info"
proxy_response="$RUNNER_TEMP/go-proxy-version-info"
proxy_headers="$RUNNER_TEMP/go-proxy-version-headers"
# An external request before tag creation can still cache a miss for 30 minutes.
max_attempts=71
for ((attempt = 1; attempt <= max_attempts; attempt++)); do
proxy_status=000
if status=$(curl --connect-timeout 10 --max-time 30 --silent --show-error --dump-header "$proxy_headers" --output "$proxy_response" --write-out '%{http_code}' "$proxy_url"); then
proxy_status=$status
fi
if [[ "$proxy_status" == 200 ]]; then
echo "Public Go proxy serves $tag"
break
fi
if [[ "$attempt" == "$max_attempts" ]]; then
echo "Public Go proxy did not serve $tag after $max_attempts attempts (last HTTP status: $proxy_status)" >&2
cat "$proxy_headers" "$proxy_response" >&2 || true
exit 1
fi
echo "Waiting for $tag on the public Go proxy (attempt $attempt/$max_attempts, HTTP $proxy_status)"
sleep 30
done
- name: Verify clean module consumption
shell: bash
env:
RELEASE_VERSION: ${{ inputs.version }}
COMMIT_SHA: ${{ inputs.commit_sha }}
run: |
set -euo pipefail
tag="v${RELEASE_VERSION}"
temp_root=$(mktemp -d)
cleanup() {
chmod -R u+w "$temp_root" 2>/dev/null || true
rm -rf "$temp_root"
}
trap cleanup EXIT
export GOMODCACHE="$temp_root/gomodcache"
export GOCACHE="$temp_root/gocache"
export GOPROXY=https://proxy.golang.org
module_dir="$temp_root/module"
mkdir -p "$GOMODCACHE" "$GOCACHE" "$module_dir"
cd "$module_dir"
go mod init example.com/qoder-release-verification
download_json=$(go mod download -json "${MODULE_PATH}@${tag}")
origin_hash=$(python3 -c 'import json, sys; print(json.load(sys.stdin).get("Origin", {}).get("Hash", ""))' <<< "$download_json")
if [[ "$origin_hash" != "$COMMIT_SHA" ]]; then
echo "Public Go proxy origin is $origin_hash, not approved commit $COMMIT_SHA." >&2
exit 1
fi
go get \
"${MODULE_PATH}/convention@${tag}" \
"${MODULE_PATH}/forward@${tag}" \
"${MODULE_PATH}/managed@${tag}"
selected_version=$(go list -m -f '{{.Version}}' "$MODULE_PATH")
if [[ "$selected_version" != "$tag" ]]; then
echo "Resolved $MODULE_PATH@$selected_version instead of $tag" >&2
exit 1
fi
cat > main.go <<EOF
package main
import (
_ "${MODULE_PATH}/convention"
_ "${MODULE_PATH}/forward"
_ "${MODULE_PATH}/managed"
)
func main() {}
EOF
gofmt -w main.go
go build .
github-release:
name: publish release notes
needs: [preflight, verify]
runs-on: ubuntu-latest
permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_COMMIT_SHA: ${{ inputs.commit_sha }}
RELEASE_PRERELEASE: ${{ contains(inputs.version, '-') }}
steps:
- name: Check out the approved commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ inputs.commit_sha }}
fetch-depth: 0
persist-credentials: false
- name: Create or verify GitHub Release
run: |
python3 .github/scripts/release_notes.py publish \
--version "$RELEASE_VERSION" \
--commit-sha "$RELEASE_COMMIT_SHA" \
--prerelease "$RELEASE_PRERELEASE"