-
Notifications
You must be signed in to change notification settings - Fork 3
421 lines (348 loc) · 13.1 KB
/
build.yml
File metadata and controls
421 lines (348 loc) · 13.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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
name: Build and Release
on:
push:
# Only trigger the heavy multi-platform build on version tag pushes (e.g. v1.10.7)
tags:
- 'v*'
# Allow manual dispatch for ad-hoc builds from the UI
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build:
name: Build for multiple platforms
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
output: filecodebox-linux-amd64
- goos: linux
goarch: arm64
output: filecodebox-linux-arm64
- goos: darwin
goarch: amd64
output: filecodebox-darwin-amd64
- goos: darwin
goarch: arm64
output: filecodebox-darwin-arm64
- goos: windows
goarch: amd64
output: filecodebox-windows-amd64.exe
- goos: windows
goarch: arm64
output: filecodebox-windows-arm64.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: make deps
- name: Run tests
run: make test
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
# 使用 Makefile 进行交叉编译
make build-cross
# 重命名输出文件以匹配矩阵配置
if [ "${{ matrix.goos }}" = "windows" ]; then
mv filecodebox filecodebox.exe
fi
mv filecodebox* ${{ matrix.output }}
- name: Create build info
run: |
echo "Build Info:" > build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
echo "Platform: ${{ matrix.goos }}/${{ matrix.goarch }}" >> build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
echo "Go Version: $(go version)" >> build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
echo "Build Time: $(date)" >> build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
echo "Commit: ${{ github.sha }}" >> build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
echo "Branch: ${{ github.ref_name }}" >> build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: filecodebox-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
${{ matrix.output }}
build-info-${{ matrix.goos }}-${{ matrix.goarch }}.txt
docker-test:
name: Test Docker build
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata for testing
id: meta-test
uses: docker/metadata-action@v5
with:
images: filecodebox-test
tags: |
type=ref,event=branch
type=raw,value=test
- name: Build Docker image for testing
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64 # 仅单平台用于测试
load: true # 加载到本地进行测试
tags: ${{ steps.meta-test.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
run: |
# 获取构建的镜像标签
IMAGE_TAG=$(echo "${{ steps.meta-test.outputs.tags }}" | head -n1)
echo "Testing image: $IMAGE_TAG"
# 启动容器进行基础测试
docker run --rm -d --name filecodebox-test -p 12346:12345 $IMAGE_TAG
# 等待服务启动
sleep 10
# 测试服务是否响应
if curl -f http://localhost:12346/ > /dev/null 2>&1; then
echo "✅ Docker 镜像测试成功"
else
echo "❌ Docker 镜像测试失败"
docker logs filecodebox-test
exit 1
fi
# 清理测试容器
docker stop filecodebox-test || true
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/zy84338719/filecodebox
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
labels: |
org.opencontainers.image.title=FileCodeBox
org.opencontainers.image.description=高性能文件分享服务 - Go语言实现
org.opencontainers.image.vendor=FileCodeBox
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}#readme
org.opencontainers.image.licenses=MIT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64 # 多平台构建用于发布
push: true # 推送到注册表
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: |
type=image,name=target,annotation-index.org.opencontainers.image.description=FileCodeBox - 高性能文件分享服务
release:
name: Create Release
runs-on: ubuntu-latest
needs: [build, docker]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Prepare release assets
run: |
mkdir -p release-assets
# 处理每个平台的构建产物
for dir in artifacts/*/; do
if [ -d "$dir" ]; then
platform=$(basename "$dir" | sed 's/filecodebox-//')
echo "Processing $platform"
# 创建发布包
cd "$dir"
# 找到可执行文件
executable=$(find . -name "filecodebox*" -executable -type f | head -1)
if [ -n "$executable" ]; then
# 创建发布目录
release_name="filecodebox-${platform}"
mkdir -p "../release-assets/$release_name"
# 复制文件
cp "$executable" "../release-assets/$release_name/"
cp build-info-*.txt "../release-assets/$release_name/" 2>/dev/null || true
# 创建README
cat > "../release-assets/$release_name/README.txt" << EOF
FileCodeBox - 文件分享服务
平台: $platform
版本: ${{ github.ref_name }}
构建时间: $(date)
使用方法:
1. 运行可执行文件启动服务
2. 访问 http://localhost:12345
3. 管理员访问 http://localhost:12345/admin
更多信息: https://github.com/${{ github.repository }}
EOF
# 打包
cd "../release-assets"
if [[ "$platform" == *"windows"* ]]; then
zip -r "${release_name}.zip" "$release_name/"
else
tar -czf "${release_name}.tar.gz" "$release_name/"
fi
rm -rf "$release_name"
fi
cd - > /dev/null
fi
done
- name: Generate release notes
run: |
# 获取当前和前一个标签
CURRENT_TAG="${{ github.ref_name }}"
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "$CURRENT_TAG" | tail -1)
# 如果没有前一个标签,使用第一个提交
if [ -z "$PREVIOUS_TAG" ] || [ "$PREVIOUS_TAG" = "$CURRENT_TAG" ]; then
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
fi
echo "生成从 $PREVIOUS_TAG 到 $CURRENT_TAG 的变更日志"
# 获取提交信息
COMMITS=$(git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG 2>/dev/null || git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD)
# 获取文件变更统计
STATS=$(git diff --stat $PREVIOUS_TAG..$CURRENT_TAG 2>/dev/null || git diff --stat $PREVIOUS_TAG..HEAD || echo "首次发布")
cat > release-notes.md << EOF
## FileCodeBox $CURRENT_TAG
### 📝 本次更新
$COMMITS
### � 变更统计
\`\`\`
$STATS
\`\`\`
### �🚀 功能特性
- ✅ 多平台可执行文件支持 (Linux, macOS, Windows)
- ✅ 支持 AMD64 和 ARM64 架构
- ✅ Docker 镜像自动构建和发布
- ✅ 文件上传下载服务
- ✅ 用户认证系统
- ✅ 管理员控制面板
- ✅ 多种存储后端支持 (本地/S3/WebDAV)
### 📦 安装方式
#### 方式一:直接下载可执行文件
选择对应平台的文件下载:
- 🐧 **Linux x64**: \`filecodebox-linux-amd64.tar.gz\`
- 🐧 **Linux ARM64**: \`filecodebox-linux-arm64.tar.gz\`
- 🍎 **macOS Intel**: \`filecodebox-darwin-amd64.tar.gz\`
- 🍎 **macOS Apple Silicon**: \`filecodebox-darwin-arm64.tar.gz\`
- 🪟 **Windows x64**: \`filecodebox-windows-amd64.zip\`
- 🪟 **Windows ARM64**: \`filecodebox-windows-arm64.zip\`
#### 方式二:Docker 部署
\`\`\`bash
# 拉取镜像
docker pull ghcr.io/zy84338719/filecodebox:$CURRENT_TAG
# 运行容器
docker run -d \\
--name filecodebox \\
-p 12345:12345 \\
-v ./data:/app/data \\
ghcr.io/zy84338719/filecodebox:$CURRENT_TAG
\`\`\`
#### 方式三:Docker Compose
\`\`\`yaml
version: '3.8'
services:
filecodebox:
image: ghcr.io/zy84338719/filecodebox:$CURRENT_TAG
ports:
- "12345:12345"
volumes:
- ./data:/app/data
restart: unless-stopped
\`\`\`
### 🔧 快速开始
1. **下载并启动服务**
- 下载对应平台的文件并解压
- 运行 \`./filecodebox\` (Linux/macOS) 或 \`filecodebox.exe\` (Windows)
2. **访问服务**
- 用户界面: http://localhost:12345
- 管理员界面: http://localhost:12345/admin
- 默认管理员密码: \`FileCodeBox2025\`
3. **基本配置**
- 修改管理员密码
- 配置存储后端
- 设置用户系统开关
### 📋 系统要求
- **操作系统**: Linux, macOS, Windows
- **架构**: AMD64 或 ARM64
- **内存**: 最小 64MB,推荐 256MB+
- **存储**: 根据使用量而定
- **网络**: HTTP/HTTPS 端口访问
### 🔒 安全说明
- 首次启动请立即修改默认管理员密码
- 生产环境建议配置 HTTPS
- 定期备份数据目录
### 🆘 问题反馈
如遇到问题,请访问:
- **GitHub Issues**: https://github.com/${{ github.repository }}/issues
- **文档**: https://github.com/${{ github.repository }}#readme
---
**构建信息**
- 构建时间: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
- Git 提交: ${{ github.sha }}
- Go 版本: $(go version | cut -d' ' -f3)
EOF
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: release-assets/*
name: FileCodeBox ${{ github.ref_name }}
body_path: release-notes.md
draft: false
prerelease: ${{ contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}