-
Notifications
You must be signed in to change notification settings - Fork 12
378 lines (325 loc) · 12.5 KB
/
release.yml
File metadata and controls
378 lines (325 loc) · 12.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*'
# 允许手动从 gh CLI 触发:gh workflow run release.yml --ref v0.1.0
# 用于重跑失败的发布,或在快速 delete+repush 同一个 tag 时手工补发
# (GitHub Actions 偶尔会跳过这种 push 事件)。
# github.ref_name 由 --ref 参数提供,与 tag 推送的语义一致。
workflow_dispatch:
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: doudou-start/airgate-core
jobs:
# ------------------------------------------------------------
# Job 1: 构建前端(只跑一次,供后续 job 复用)
# ------------------------------------------------------------
build-frontend:
name: Build Frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Clone airgate-sdk
run: git clone --depth 1 https://github.com/DouDOU-start/airgate-sdk.git ../airgate-sdk
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: web/package-lock.json
- name: Build @airgate/theme (sdk frontend dependency)
run: cd ../airgate-sdk/frontend && npm ci && npm run build
- name: Build core frontend
run: cd web && npm ci && npm run build
- name: Upload web/dist artifact
uses: actions/upload-artifact@v4
with:
name: web-dist
path: web/dist
retention-days: 1
# ------------------------------------------------------------
# Job 2: 多架构 Docker 镜像(原生 runner 并行构建,无 QEMU)
# ------------------------------------------------------------
build-image:
name: Build Image (${{ matrix.platform }})
needs: build-frontend
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout airgate-core
uses: actions/checkout@v4
with:
path: airgate-core
- name: Clone airgate-sdk
run: git clone --depth 1 https://github.com/DouDOU-start/airgate-sdk.git airgate-sdk
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: web-dist
path: airgate-core/web/dist
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build & push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
file: airgate-core/deploy/Dockerfile
platforms: ${{ matrix.platform }}
build-args: |
VERSION=${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
provenance: false
sbom: false
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# ------------------------------------------------------------
# Job 3: 合并多架构 manifest
# ------------------------------------------------------------
merge-manifests:
name: Merge Multi-arch Manifest
needs: build-image
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
# ------------------------------------------------------------
# Job 4: 跨平台原生二进制(linux/darwin × amd64/arm64)
# 用于裸金属 install.sh 部署 —— 二进制完全自包含,前端 SPA + 翻译文件
# 都已 //go:embed 进 binary,不需要附加资源。
# ------------------------------------------------------------
build-binaries:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
needs: build-frontend
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- uses: actions/checkout@v4
- name: Clone airgate-sdk (go.work replace)
run: git clone --depth 1 https://github.com/DouDOU-start/airgate-sdk.git ../airgate-sdk
- name: Create go.work to use cloned airgate-sdk
# 让 backend 的 Go 构建直接使用 sibling 的 airgate-sdk master,
# 避免每次 SDK 新增字段都要手动 bump backend/go.mod。
# 本地开发 go.work 在 gitignore,CI/release 临时生成一份。
run: |
cat > go.work <<'EOF'
go 1.25.7
use (
./backend
../airgate-sdk
)
EOF
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: web-dist
path: web/dist
- name: Embed web/dist into backend
run: |
rm -rf backend/internal/web/webdist
mkdir -p backend/internal/web/webdist
cp -r web/dist/. backend/internal/web/webdist/
- uses: actions/setup-go@v5
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- name: Build airgate-core binary
env:
GOTOOLCHAIN: local
CGO_ENABLED: 0
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
VERSION="${GITHUB_REF_NAME}"
echo "Injecting Version=${VERSION}"
mkdir -p bin
cd backend && go build -buildvcs=false -trimpath \
-ldflags "-X 'github.com/DouDOU-start/airgate-core/internal/version.Version=${VERSION}' -s -w" \
-o ../bin/airgate-core-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/server
- name: Generate SHA256
run: |
cd bin && sha256sum airgate-core-${{ matrix.goos }}-${{ matrix.goarch }} \
> airgate-core-${{ matrix.goos }}-${{ matrix.goarch }}.sha256
- name: Upload binary artifacts
uses: actions/upload-artifact@v4
with:
name: airgate-core-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
bin/airgate-core-${{ matrix.goos }}-${{ matrix.goarch }}
bin/airgate-core-${{ matrix.goos }}-${{ matrix.goarch }}.sha256
retention-days: 1
# ------------------------------------------------------------
# Job 5: 创建 GitHub Release,把 docker tag 与原生二进制聚合发布
# ------------------------------------------------------------
release-notes:
name: Create GitHub Release
needs:
- merge-manifests
- build-binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all binary artifacts
uses: actions/download-artifact@v4
with:
path: dist
# 必须显式 filter,否则 docker/build-push-action@v6 自动产生的
# *.dockerbuild 缓存元数据也会被列入,且下载会失败 5 次重试。
pattern: airgate-core-*-*
merge-multiple: true
- name: List collected artifacts
run: ls -la dist/
- name: Generate release body
env:
CURRENT_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
git fetch --force --tags
prev_tag="$(git describe --tags --abbrev=0 "${CURRENT_TAG}^" 2>/dev/null || true)"
if [ -n "$prev_tag" ]; then
range="${prev_tag}..${CURRENT_TAG}"
else
range="${CURRENT_TAG}"
fi
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
touch \
"$tmp_dir/feat.txt" \
"$tmp_dir/fix.txt" \
"$tmp_dir/refactor.txt" \
"$tmp_dir/perf.txt" \
"$tmp_dir/docs.txt" \
"$tmp_dir/other.txt"
while IFS= read -r subject; do
[ -n "$subject" ] || continue
bucket="other"
item="$subject"
if [[ "$subject" =~ ^([[:alpha:]]+)(\(([[:alnum:]_.\/-]+)\))?(!)?:[[:space:]]*(.+)$ ]]; then
type="${BASH_REMATCH[1],,}"
scope="${BASH_REMATCH[3]}"
message="${BASH_REMATCH[5]}"
item="$message"
if [ -n "$scope" ]; then
item="$scope: $message"
fi
case "$type" in
feat|fix|refactor|perf|docs)
bucket="$type"
;;
esac
fi
printf '%s\n' "$item" >> "$tmp_dir/$bucket.txt"
done < <(git log --no-merges --pretty=format:%s "$range")
append_section() {
local title="$1"
local file="$2"
if [ -s "$file" ]; then
printf '### %s\n\n' "$title" >> release_body.md
while IFS= read -r line; do
printf -- '- %s\n' "$line" >> release_body.md
done < "$file"
printf '\n' >> release_body.md
fi
}
printf '## 本版本变更\n\n' > release_body.md
if [ -n "$prev_tag" ]; then
printf '> 变更范围:`%s..%s`\n\n' "$prev_tag" "$CURRENT_TAG" >> release_body.md
else
printf '> 变更范围:初始发布\n\n' >> release_body.md
fi
append_section '新增' "$tmp_dir/feat.txt"
append_section '修复' "$tmp_dir/fix.txt"
append_section '重构' "$tmp_dir/refactor.txt"
append_section '性能优化' "$tmp_dir/perf.txt"
append_section '文档' "$tmp_dir/docs.txt"
append_section '其他调整' "$tmp_dir/other.txt"
if [ ! -s "$tmp_dir/feat.txt" ] && [ ! -s "$tmp_dir/fix.txt" ] && [ ! -s "$tmp_dir/refactor.txt" ] && [ ! -s "$tmp_dir/perf.txt" ] && [ ! -s "$tmp_dir/docs.txt" ] && [ ! -s "$tmp_dir/other.txt" ]; then
printf -- '- 本版本没有检测到可汇总的提交记录。\n\n' >> release_body.md
fi
- name: Create release with generated changelog
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body_path: release_body.md
files: |
dist/airgate-core-*