11# 打包与发布
22
3- csghub-lite 使用 [ GoReleaser ] ( https://goreleaser.com ) 进行跨平台构建和发布 。
3+ csghub-lite 当前以本地 ` make package ` + ` scripts/push.sh ` 手动发布为主。GoReleaser 仍然保留用于定义归档格式、生成 GitHub Release 产物,以及执行本地 snapshot 验证,但不再负责 Homebrew tap 发布 。
44
55## 支持的分发形式
66
77| 分发方式 | 平台 | 文件/命令 |
88| ---------| ------| -----------|
9- | 一键安装脚本 | Linux / macOS | ` curl -fsSL ... /install.sh \| sh ` |
10- | Homebrew | macOS / Linux | ` brew install csghub-lite ` |
9+ | 一键安装脚本 | Linux / macOS | ` curl -fsSL https://hub.opencsg.com/csghub-lite /install.sh \| sh ` |
10+ | Homebrew | macOS | ` brew tap opencsgs/csghub-lite https://github.com/OpenCSGs/csghub-lite && brew install opencsgs/csghub-lite/ csghub-lite` |
1111| tar.gz | macOS / Linux | GitHub Releases |
1212| zip | Windows | GitHub Releases |
1313| deb | Debian / Ubuntu | GitHub Releases |
1414| rpm | RHEL / CentOS / Fedora | GitHub Releases |
1515| 源码编译 | 全平台 | ` make build ` |
1616
17- ## 构建
18-
19- ### 本地构建
17+ ## 本地构建
2018
2119``` bash
2220# 构建当前平台
@@ -25,133 +23,93 @@ make build
2523# 构建全平台
2624make build-all
2725
28- # 二进制文件输出到 bin/ 目录
29- ls bin/
30- csghub-lite # 当前平台
31- csghub-lite-darwin-arm64 # macOS Apple Silicon
32- csghub-lite-darwin-amd64 # macOS Intel
33- csghub-lite-linux-amd64 # Linux x86_64
34- csghub-lite-linux-arm64 # Linux ARM64
35- csghub-lite-windows-amd64.exe # Windows
26+ # 打包发布产物
27+ make package
3628```
3729
38- ` make build ` 、` make build-all ` 与 ` make package ` 都会先构建 ` web ` 并同步到 ` internal/server/static ` ,确保发布二进制内嵌 Web UI。
30+ ` make build ` 、` make build-all ` 与 ` make package ` 都会先构建 ` web ` 并同步到 ` internal/server/static ` ,确保发布二进制内嵌 Web UI。` make package ` 还会额外生成 ` dist/checksums.txt ` ,供 Homebrew formula 和发布校验复用。
3931
40- ### 版本号
32+ ## 版本号
4133
42- 版本号通过 ` git tag ` 管理,自动嵌入二进制文件 :
34+ 版本号通过 ` git tag ` 管理,并在构建时注入二进制 :
4335
4436``` bash
4537git tag v0.1.0
4638git push origin v0.1.0
4739```
4840
49- 本地开发时版本号为 ` dev ` 。
50-
51- ## GoReleaser 配置
52-
53- 配置文件: ` .goreleaser.yml `
54-
55- ### 核心设置
56-
57- ``` yaml
58- builds :
59- - id : csghub-lite
60- main : ./cmd/csghub-lite
61- env :
62- - CGO_ENABLED=0 # 纯 Go 编译,无 CGO 依赖
63- goos : [linux, darwin, windows]
64- goarch : [amd64, arm64]
65- ldflags :
66- - -s -w -X main.version={{.Version}}
67- ` ` `
68-
69- ### 包格式
70-
71- - **tar.gz**: Linux / macOS 默认
72- - **zip**: Windows 默认
73- - **deb / rpm**: 通过 NFPM 生成
74-
75- ### Homebrew Tap
76-
77- GoReleaser 自动将 Homebrew formula 推送到 ` opencsgs/homebrew-tap` 仓库。需要配置 `HOMEBREW_TAP_TOKEN` secret。
78-
79- # # CI/CD
80-
81- 通过 GitHub Actions 自动化,配置文件 : ` .github/workflows/ci.yml`
82-
83- # ## 触发条件
84-
85- - **Push / PR 到 main**: 运行测试
86- - **Push tag `v*`**: 运行测试 + GoReleaser 发布
41+ 未打 tag 的本地开发构建默认显示为 ` dev ` 。
8742
88- # ## 发布流程
43+ ## 推荐发布流程
8944
9045``` bash
9146# 1. 确保测试通过
9247make test
9348
94- # 2. 创建版本标签
49+ # 2. 创建发布 tag
9550git tag v0.1.0
9651
97- # 3. 推送标签(触发 CI 自动发布)
98- git push origin v0.1.0
99- ` ` `
52+ # 3. 本地打包(会构建 web 并生成 dist/checksums.txt)
53+ make package
10054
101- CI 自动执行:
55+ # 4. 更新仓库内 Homebrew formula
56+ ./scripts/update-homebrew-formula.sh --tag v0.1.0
10257
103- 1. 运行所有测试
104- 2. GoReleaser 交叉编译所有平台
105- 3. 上传到 GitHub Releases
106- 4. 更新 Homebrew tap
107- 5. 生成 deb / rpm 包
58+ # 5. 上传 GitHub / GitLab release 资产
59+ ./scripts/push.sh --skip-build --tag v0.1.0
60+ ```
10861
109- # ## GitLab 同步(CSGHub / 国内安装源)
62+ 说明:
11063
111- 推送 `v*` 标签只会触发 **GitHub** 上的 GoReleaser 发布;**GitLab** 上的 Release 与 Generic Package 需要单独上传,否则 `install.sh` 在国内(CN)从 GitLab 拉取时会缺包。
64+ - ` scripts/push.sh ` 会将本地 ` dist/ ` 下的发布包上传到 GitHub Release 和 GitLab Generic Package/Release。
65+ - GitLab 上传会自动从 ` local/secrets.env ` 读取 ` GITLAB_TOKEN ` (如果环境变量未设置)。
66+ - 如果你希望仓库中的 ` Formula/csghub-lite.rb ` 始终指向“最新正式版”,请在发布完成后提交该文件的更新。
11267
113- **推荐(自动化)**:在 GitHub 仓库 **Settings → Secrets and variables → Actions** 中新增 `GITLAB_TOKEN`( GitLab 个人访问令牌,`api` 权限)。发布工作流在 GoReleaser 成功后会调用 `scripts/push.sh`,将五个平台压缩包同步到 `git-devops.opencsg.com` 上与本项目 `scripts/push.sh` 一致的 Generic Package 路径。未配置该 secret 时此步骤跳过,行为与以前一致。
68+ ## GitLab 补发
11469
115- **手动补发某个版本**(例如已发 GitHub 但未发 GitLab) :
70+ 如果某个版本已经发到了 GitHub,但 GitLab 资产缺失,可以先把 release 文件拉回本地再补发 :
11671
11772``` bash
118- # 从 GitHub Release 拉取 GoReleaser 产物到 dist/
11973gh release download v0.5.10 --repo OpenCSGs/csghub-lite -D dist/
120-
121- # 文件名改为与 install.sh / push.sh 一致(OS-ARCH 用连字符)
12274./scripts/rename-dist-for-gitlab.sh 0.5.10
123-
124- export GITLAB_TOKEN="glpat-..." # 或写入 local/secrets.env 后由 push.sh 自动加载
12575./scripts/push.sh --skip-github --skip-build --skip-gitlab-git --tag v0.5.10
12676```
12777
128- 本地从零构建再上传时,检出对应 tag 后执行 `make package`,确认产物已内嵌最新 Web UI,然后执行 `scripts/push.sh --skip-github --skip-build --tag vX.Y.Z`(会包含向 GitLab 推送 tag,除非加 `--skip-gitlab-git`)。
78+ ## 安装脚本
12979
130- # ## 本地测试发布
80+ 主安装入口保持不变:
13181
13282``` bash
133- # GoReleaser 本地快照(不实际发布)
134- make release-snapshot
83+ curl -fsSL https://hub.opencsg.com/csghub-lite/install.sh | sh
84+ ```
13585
136- # 输出到 dist/ 目录
137- ls dist/
86+ ` scripts/install.sh ` 会自动检测 OS 和 CPU 架构,优先从 GitHub/GitLab release 资产下载最新版本,并在需要时安装或升级 ` llama-server ` 。
87+
88+ 指定版本安装:
89+
90+ ``` bash
91+ CSGHUB_LITE_VERSION=v0.1.0 curl -fsSL https://hub.opencsg.com/csghub-lite/install.sh | sh
13892```
13993
140- # # 安装脚本
94+ ## Homebrew Formula
95+
96+ Homebrew 现在是 repo 内维护的额外入口,主要面向 macOS。主仓库本身充当自定义 tap,不依赖独立的 ` homebrew-tap ` 仓库,也不需要向 Homebrew 上传二进制文件。
14197
142- ` scripts/ install.sh` 提供一键安装:
98+ Linux 的正式安装文档仍以 ` install.sh ` 、release 压缩包和 ` deb/rpm ` 为主。
14399
144- - 自动检测 OS 和 CPU 架构
145- - 从 GitHub Releases 下载最新版本
146- - 解压并安装到 `/usr/local/bin`
147- - 检查 `llama-server` 是否可用
100+ - Formula 文件位于 ` Formula/csghub-lite.rb `
101+ - 更新脚本位于 ` scripts/update-homebrew-formula.sh `
102+ - 该脚本读取 ` dist/checksums.txt ` ,将当前 release 的 URL 和 SHA256 写回 formula
148103
149- 支持指定版本 :
104+ 用户先把主仓库 tap 进 Homebrew,再安装对应 formula :
150105
151106``` bash
152- CSGHUB_LITE_VERSION=v0.1.0 curl -fsSL .../install.sh | sh
107+ brew tap opencsgs/csghub-lite https://github.com/OpenCSGs/csghub-lite
108+ brew install opencsgs/csghub-lite/csghub-lite
153109```
154110
155- # # Homebrew Formula
111+ ## GoReleaser 与 CI
156112
157- 独立的 Homebrew formula 位于 `Formula/csghub-lite.rb`,主要用于本地测试。正式发布由 GoReleaser 自动推送到 `opencsgs/homebrew-tap`。
113+ - ` .goreleaser.yml ` 继续定义 archive、checksum、nfpm 和 GitHub release 相关配置
114+ - ` make release-snapshot ` 可在本地验证 GoReleaser 输出
115+ - GitHub Actions 仍会在 tag 上构建 release 产物,但仓库约定的正式发布方式仍然是本地打包后手动上传
0 commit comments