-
Notifications
You must be signed in to change notification settings - Fork 0
298 lines (250 loc) · 11.1 KB
/
agent-release.yml
File metadata and controls
298 lines (250 loc) · 11.1 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
name: Publish Agent Release
on:
push:
branches:
- main
tags:
- agent-v*
paths:
- .github/workflows/agent-release.yml
- CHANGELOG.md
- cmd/**
- internal/**
- scripts/**
- go.mod
- go.sum
- README.md
- config.example.json
workflow_dispatch:
inputs:
release_version:
description: Optional existing tagged release version such as 0.1.0
required: false
type: string
publish_latest:
description: Also refresh the latest channel
required: true
default: true
type: boolean
concurrency:
group: agent-release-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
publish:
name: Build and publish agent artifacts
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_REGION: auto
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
PUBLIC_RELEASE_BASE_URL: https://cdn.noderax.net/noderax-agent/releases
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Verify dependencies
run: go mod verify
- name: Test
run: go test ./...
- name: Resolve release metadata
id: release
shell: bash
run: |
set -euo pipefail
trim() {
local value="${1:-}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
printf '%s' "${value}"
}
release_version=""
publish_latest="true"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
release_version="$(trim "${{ inputs.release_version }}")"
publish_latest="${{ inputs.publish_latest }}"
elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="$(trim "${GITHUB_REF_NAME#agent-v}")"
fi
if [[ -n "${release_version}" && ! "${release_version}" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "Release version must be URL-safe. Got: ${release_version}" >&2
exit 1
fi
if [[ -n "${release_version}" ]]; then
if ! git rev-parse --verify "refs/tags/agent-v${release_version}" >/dev/null 2>&1; then
echo "Versioned releases must map to an existing git tag agent-v${release_version}." >&2
exit 1
fi
fi
binary_version="${release_version}"
if [[ -z "${binary_version}" ]]; then
binary_version="main-${GITHUB_SHA::7}"
fi
build_date="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}"
echo "binary_version=${binary_version}" >> "${GITHUB_OUTPUT}"
echo "publish_latest=${publish_latest}" >> "${GITHUB_OUTPUT}"
echo "build_date=${build_date}" >> "${GITHUB_OUTPUT}"
- name: Build release assets
shell: bash
run: |
set -euo pipefail
chmod +x ./scripts/build-release.sh
./scripts/build-release.sh \
--version "${{ steps.release.outputs.binary_version }}" \
--commit "${GITHUB_SHA}" \
--build-date "${{ steps.release.outputs.build_date }}" \
--output-dir "./dist/release"
- name: Generate tagged release metadata
if: steps.release.outputs.release_version != ''
shell: bash
run: |
set -euo pipefail
version="${{ steps.release.outputs.release_version }}"
download_base_url="${PUBLIC_RELEASE_BASE_URL}/${version}"
go run ./cmd/release-metadata bundle \
--version "${version}" \
--commit "${GITHUB_SHA}" \
--published-at "${{ steps.release.outputs.build_date }}" \
--artifacts-dir "./dist/release" \
--download-base-url "${download_base_url}" \
--manifest-output "./dist/release/release-manifest.json" \
--release-notes-output "./dist/release/release-notes.md" \
--changelog "./CHANGELOG.md"
if curl -fsSL "${PUBLIC_RELEASE_BASE_URL}/catalog.json" -o "./dist/release/catalog-existing.json"; then
echo "Loaded existing CDN catalog."
else
printf '{\"releases\":[]}\n' > "./dist/release/catalog-existing.json"
fi
go run ./cmd/release-metadata catalog \
--manifest "./dist/release/release-manifest.json" \
--existing "./dist/release/catalog-existing.json" \
--output "./dist/release/catalog.json"
- name: Show release assets
run: ls -lah ./dist/release
- name: Validate R2 configuration
id: r2
shell: bash
run: |
set -euo pipefail
trim() {
local value="${1:-}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
printf '%s' "${value}"
}
: "${AWS_ACCESS_KEY_ID:?Missing R2_ACCESS_KEY_ID secret}"
: "${AWS_SECRET_ACCESS_KEY:?Missing R2_SECRET_ACCESS_KEY secret}"
: "${R2_ACCOUNT_ID:?Missing R2_ACCOUNT_ID secret}"
: "${R2_BUCKET:?Missing R2_BUCKET secret}"
raw_bucket="$(trim "${R2_BUCKET}")"
if [[ "${raw_bucket}" == s3://* ]]; then
raw_bucket="${raw_bucket#s3://}"
fi
if [[ "${raw_bucket}" == http://* || "${raw_bucket}" == https://* ]]; then
path_part="${raw_bucket#http://}"
path_part="${path_part#https://}"
if [[ "${path_part}" != */* ]]; then
echo "R2_BUCKET must be the bucket name only, not a URL without a bucket path." >&2
echo "Example: media-assets" >&2
exit 1
fi
raw_bucket="${path_part#*/}"
fi
raw_bucket="${raw_bucket#/}"
raw_bucket="${raw_bucket%%/*}"
if [[ -z "${raw_bucket}" ]]; then
echo "Resolved R2 bucket name is empty. Set R2_BUCKET to your bucket name, for example media-assets." >&2
exit 1
fi
if [[ ! "${raw_bucket}" =~ ^[a-zA-Z0-9._-]{1,255}$ ]]; then
echo "Resolved R2 bucket name is invalid: ${raw_bucket}" >&2
echo "Set R2_BUCKET to the plain bucket name only, without https:// or extra path segments." >&2
exit 1
fi
echo "bucket_name=${raw_bucket}" >> "${GITHUB_OUTPUT}"
echo "endpoint_url=https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" >> "${GITHUB_OUTPUT}"
aws --version
- name: Verify R2 bucket exists
shell: bash
run: |
set -euo pipefail
endpoint="${{ steps.r2.outputs.endpoint_url }}"
bucket="${{ steps.r2.outputs.bucket_name }}"
if ! aws s3api head-bucket --bucket "${bucket}" --endpoint-url "${endpoint}" >/dev/null 2>&1; then
echo "R2 bucket '${bucket}' was not found for the configured account/credentials." >&2
echo "Check that R2_BUCKET matches the exact bucket name in Cloudflare R2." >&2
echo "Also confirm R2_ACCOUNT_ID and the access keys belong to the same Cloudflare account as that bucket." >&2
exit 1
fi
- name: Publish installer and latest channel
if: steps.release.outputs.publish_latest == 'true'
shell: bash
run: |
set -euo pipefail
endpoint="${{ steps.r2.outputs.endpoint_url }}"
bucket="s3://${{ steps.r2.outputs.bucket_name }}"
aws s3 cp ./dist/release/install.sh "${bucket}/noderax-agent/install.sh" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=300" \
--content-type "text/x-shellscript; charset=utf-8"
aws s3 cp ./dist/release/noderax-agent-linux-amd64 "${bucket}/noderax-agent/releases/latest/noderax-agent-linux-amd64" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=300" \
--content-type "application/octet-stream"
aws s3 cp ./dist/release/noderax-agent-linux-arm64 "${bucket}/noderax-agent/releases/latest/noderax-agent-linux-arm64" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=300" \
--content-type "application/octet-stream"
aws s3 cp ./dist/release/SHA256SUMS "${bucket}/noderax-agent/releases/latest/SHA256SUMS" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=300" \
--content-type "text/plain; charset=utf-8"
- name: Publish versioned release and catalog
if: steps.release.outputs.release_version != ''
shell: bash
run: |
set -euo pipefail
endpoint="${{ steps.r2.outputs.endpoint_url }}"
bucket="s3://${{ steps.r2.outputs.bucket_name }}"
version="${{ steps.release.outputs.release_version }}"
aws s3 cp ./dist/release/noderax-agent-linux-amd64 "${bucket}/noderax-agent/releases/${version}/noderax-agent-linux-amd64" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=31536000, immutable" \
--content-type "application/octet-stream"
aws s3 cp ./dist/release/noderax-agent-linux-arm64 "${bucket}/noderax-agent/releases/${version}/noderax-agent-linux-arm64" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=31536000, immutable" \
--content-type "application/octet-stream"
aws s3 cp ./dist/release/SHA256SUMS "${bucket}/noderax-agent/releases/${version}/SHA256SUMS" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=31536000, immutable" \
--content-type "text/plain; charset=utf-8"
aws s3 cp ./dist/release/release-manifest.json "${bucket}/noderax-agent/releases/${version}/release-manifest.json" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=31536000, immutable" \
--content-type "application/json; charset=utf-8"
aws s3 cp ./dist/release/catalog.json "${bucket}/noderax-agent/releases/catalog.json" \
--endpoint-url "${endpoint}" \
--cache-control "public, max-age=300" \
--content-type "application/json; charset=utf-8"
- name: Publish GitHub Release metadata
if: steps.release.outputs.release_version != ''
uses: softprops/action-gh-release@v2
with:
tag_name: agent-v${{ steps.release.outputs.release_version }}
name: Noderax Agent ${{ steps.release.outputs.release_version }}
body_path: ./dist/release/release-notes.md
fail_on_unmatched_files: true
files: |
./dist/release/noderax-agent-linux-amd64
./dist/release/noderax-agent-linux-arm64
./dist/release/SHA256SUMS
./dist/release/release-manifest.json