Skip to content

Commit f022c4e

Browse files
authored
Merge pull request #11 from shenyanshu/main
chore: 添加自动构建二进制文件功能。
2 parents 4825a35 + 75add52 commit f022c4e

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/build-go.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# .github/workflows/build.yml
2+
3+
name: Build and Package gpt_load
4+
5+
# 工作流触发条件
6+
on:
7+
# 1. 自动触发:当代码推送到 main 分支时
8+
push:
9+
branches:
10+
- main
11+
# 2. 自动触发:当向 main 分支发起 Pull Request 时
12+
pull_request:
13+
branches:
14+
- main
15+
# 3. 手动触发:允许在 Actions 页面手动运行此工作流
16+
workflow_dispatch:
17+
18+
jobs:
19+
build-and-package:
20+
# 指定运行环境
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
# 1. 检出代码
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
# 2. 设置 Go 环境
29+
- name: Setup Go environment
30+
uses: actions/setup-go@v5
31+
with:
32+
go-version: '1.22.x'
33+
34+
# 3. 设置 Node.js 环境 (用于编译 Vue)
35+
- name: Setup Node.js environment
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '20.x'
39+
cache: 'npm'
40+
cache-dependency-path: 'web/package-lock.json'
41+
42+
# 4. 构建 Vue 前端
43+
- name: Build Vue Frontend
44+
run: npm install && npm run build
45+
working-directory: ./web
46+
47+
# 5. 编译 Go 应用
48+
# 我们将编译后的二进制文件命名为 gpt_load
49+
- name: Build Go Application
50+
run: go build -v -ldflags="-s -w" -o gpt_load ./main.go
51+
52+
# 6. 准备用于打包的目录
53+
# 将 gpt_load 和 dist 目录移入打包目录
54+
- name: Prepare Package Directory
55+
run: |
56+
mkdir release_package
57+
mv gpt_load release_package/
58+
mv web/dist release_package/
59+
60+
# 7. 创建压缩包
61+
# 将压缩包命名为 gpt_load-linux-amd64.tar.gz
62+
- name: Create Compressed Archive
63+
run: tar -czvf gpt_load-linux-amd64.tar.gz -C release_package .
64+
65+
# 8. 上传最终的压缩包作为产物
66+
- name: Upload Release Package
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: gpt_load-package-linux-amd64 # Artifact的名称也更新
70+
path: gpt_load-linux-amd64.tar.gz # 上传更新后的压缩文件

0 commit comments

Comments
 (0)