-
Notifications
You must be signed in to change notification settings - Fork 213
390 lines (343 loc) · 11.7 KB
/
Copy pathbuild-release.yml
File metadata and controls
390 lines (343 loc) · 11.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
name: Build and Release Multi-Platform
on:
push:
tags:
- 'v*'
branches:
- '**'
paths-ignore:
# 文档文件(不包括 skill-sublinkpro,它会被嵌入到二进制文件中)
- '*.md'
- 'docs/**'
# AI 代理配置和私有文档
- '.agents/**'
- '.claude/**'
- '.codex/**'
- 'AGENTS.md'
- 'CLAUDE.md'
- 'GEMINI.md'
- 'CONTRIBUTING.md'
# 编辑器/IDE 配置
- '.vscode/**'
- '.idea/**'
- '.editorconfig'
# Git 配置
- '.gitignore'
- '.gitattributes'
# 许可证文件
- 'LICENSE'
- 'COPYING'
permissions:
contents: write
packages: write
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: '24'
# cache: 'yarn' # Disabled to prevent using system Yarn v1 which conflicts with Corepack Yarn v4
- name: Enable Corepack
run: corepack enable
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
cd webs
echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v6
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('webs/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install frontend dependencies
run: |
cd webs
yarn install --immutable
- name: Lint frontend
run: |
cd webs
yarn run lint
- name: Build frontend
run: |
cd webs
yarn run build
- name: Upload frontend artifacts
uses: actions/upload-artifact@v7
with:
name: frontend-dist
path: webs/dist/
retention-days: 1
backend-quality:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.26.4'
cache: true
cache-dependency-path: go.sum
- name: Download Go modules
run: go mod download
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12.2
- name: Run Go tests
run: go test ./...
# 使用矩阵策略并发构建不同架构的二进制文件
build-go-binaries:
needs: [build-frontend, backend-quality]
runs-on: ubuntu-latest
strategy:
fail-fast: false # 允许其他架构继续构建,即使某个失败
matrix:
include:
- goos: linux
goarch: amd64
output: sublinkPro-linux-amd64
upx: true
- goos: linux
goarch: arm64
output: sublinkPro-linux-arm64
upx: true
- goos: linux
goarch: arm
goarm: 7
output: sublinkPro-linux-armv7
upx: true
- goos: linux
goarch: 386
output: sublinkPro-linux-x86
upx: true
- goos: windows
goarch: amd64
output: sublinkPro-windows-amd64.exe
upx: false
- goos: windows
goarch: 386
output: sublinkPro-windows-x86.exe
upx: false
- goos: darwin
goarch: amd64
output: sublinkPro-darwin-amd64
upx: false
- goos: darwin
goarch: arm64
output: sublinkPro-darwin-arm64
upx: false
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.26.4'
cache: true
cache-dependency-path: go.sum
- name: Download frontend artifacts
uses: actions/download-artifact@v8
with:
name: frontend-dist
path: static/
- name: Write version to VERSION file
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
else
TAG_NAME=$(git rev-parse --short HEAD)
fi
echo "$TAG_NAME" > VERSION
echo "Written version $TAG_NAME to VERSION file"
- name: Build Go binary for ${{ matrix.goos }}/${{ matrix.goarch }}
run: |
mkdir -p build
echo "Building ${{ matrix.output }} for ${{ matrix.goos }}/${{ matrix.goarch }}..."
if [ -n "${{ matrix.goarm }}" ]; then
export GOARM="${{ matrix.goarm }}"
echo "Using GOARM=${GOARM}"
fi
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
go build -tags=prod -ldflags="-s -w" -o build/${{ matrix.output }} .
echo "Build completed. Binary size:"
ls -lh build/${{ matrix.output }}
- name: Compress binary with UPX
if: matrix.upx
run: |
# 安装 UPX
sudo apt-get update && sudo apt-get install -y upx
echo "=== Original binary size ==="
ls -lh build/${{ matrix.output }}
# 使用最佳压缩率压缩 Linux 二进制文件
upx --best --lzma build/${{ matrix.output }} || true
echo "=== Compressed binary size ==="
ls -lh build/${{ matrix.output }}
- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: binary-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/${{ matrix.output }}
retention-days: 1
# 合并所有架构的二进制文件
merge-binaries:
needs: build-go-binaries
runs-on: ubuntu-latest
steps:
- name: Download all binary artifacts
uses: actions/download-artifact@v8
with:
pattern: binary-*
path: build/
merge-multiple: true
- name: Verify all binaries
run: |
echo "=== All binary files ==="
ls -lh build/
# 验证所有必需的二进制文件都存在
REQUIRED_FILES=(
"sublinkPro-linux-amd64"
"sublinkPro-linux-arm64"
"sublinkPro-linux-armv7"
"sublinkPro-linux-x86"
"sublinkPro-windows-amd64.exe"
"sublinkPro-windows-x86.exe"
"sublinkPro-darwin-amd64"
"sublinkPro-darwin-arm64"
)
MISSING=0
for file in "${REQUIRED_FILES[@]}"; do
if [ ! -f "build/$file" ]; then
echo "ERROR: Missing required binary: $file"
MISSING=1
else
echo "OK: $file exists"
fi
done
if [ $MISSING -eq 1 ]; then
echo "ERROR: Some required binaries are missing!"
exit 1
fi
echo "=== All binaries verified successfully ==="
- name: Upload merged binaries
uses: actions/upload-artifact@v7
with:
name: go-binaries
path: build/
retention-days: 1
release:
if: startsWith(github.ref, 'refs/tags/')
needs: merge-binaries
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download binary artifacts
uses: actions/download-artifact@v8
with:
name: go-binaries
path: build/
- name: Generate changelog
id: changelog
run: |
CURRENT_TAG=${GITHUB_REF#refs/tags/}
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
if [ -z "$PREVIOUS_TAG" ]; then
echo "## 🎉 首次发布" > changelog.md
echo "" >> changelog.md
echo "### 📝 所有提交:" >> changelog.md
git log --pretty=format:"- %s (%h)" >> changelog.md
else
echo "## 🚀 更新内容 ($PREVIOUS_TAG -> $CURRENT_TAG)" > changelog.md
echo "" >> changelog.md
echo "### 📝 提交记录:" >> changelog.md
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG >> changelog.md
fi
echo "" >> changelog.md
echo "### 📦 发布文件:" >> changelog.md
echo "- \`sublinkPro-linux-amd64\` - Linux x64" >> changelog.md
echo "- \`sublinkPro-linux-arm64\` - Linux ARM64" >> changelog.md
echo "- \`sublinkPro-linux-armv7\` - Linux ARMv7 (32-bit)" >> changelog.md
echo "- \`sublinkPro-linux-x86\` - Linux x86 (32-bit)" >> changelog.md
echo "- \`sublinkPro-windows-amd64.exe\` - Windows x64" >> changelog.md
echo "- \`sublinkPro-windows-x86.exe\` - Windows x86 (32-bit)" >> changelog.md
echo "- \`sublinkPro-darwin-amd64\` - macOS x64" >> changelog.md
echo "- \`sublinkPro-darwin-arm64\` - macOS ARM64 (Apple Silicon)" >> changelog.md
- name: Create Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.changelog.outputs.current_tag }}
name: Release ${{ steps.changelog.outputs.current_tag }}
body_path: changelog.md
files: |
build/sublinkPro-linux-amd64
build/sublinkPro-linux-arm64
build/sublinkPro-linux-armv7
build/sublinkPro-linux-x86
build/sublinkPro-windows-amd64.exe
build/sublinkPro-windows-x86.exe
build/sublinkPro-darwin-amd64
build/sublinkPro-darwin-arm64
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-docker:
needs: [build-frontend, merge-binaries]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Download frontend artifacts
uses: actions/download-artifact@v8
with:
name: frontend-dist
path: static/
- name: Download binary artifacts
uses: actions/download-artifact@v8
with:
name: go-binaries
path: build/
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
# 带 tag 的推送:使用 tag 版本号 + latest
TAG=${GITHUB_REF#refs/tags/}
docker buildx build --no-cache --pull --platform linux/amd64,linux/arm64,linux/arm/v7,linux/386 \
-f Dockerfile.ci \
-t zerodeng/sublink-pro:${TAG} \
-t zerodeng/sublink-pro:latest \
--push .
else
# 分支推送:dev 和 main 分支统一使用 dev 标签,其他分支使用分支名
BRANCH=${GITHUB_REF#refs/heads/}
if [[ "$BRANCH" == "dev" || "$BRANCH" == "main" ]]; then
DOCKER_TAG="dev"
else
# 将分支名中的 / 替换为 - 以兼容 Docker tag 格式
DOCKER_TAG=${BRANCH//\//-}
fi
docker buildx build --no-cache --pull --platform linux/amd64,linux/arm64,linux/arm/v7,linux/386 \
-f Dockerfile.ci \
-t zerodeng/sublink-pro:${DOCKER_TAG} \
--push .
fi