aa7099ba94
将单一 CI/CD 流水线拆成三条互不影响的发布流水线,各有 tag 前缀、独立版本
序列与独立 CHANGELOG:
- client(client-v*):Flutter 全平台 + version.yaml 自更新清单
- site(site-v*):web/ Eleventy 营销站,不含 web 版 app
- server(server-v*):backend Go 服务 + 共享基建 nginx/systemd
新增 3 个 workflow(deploy-client/site/server.yml)替换 deploy.yml;CI 脚本
按 part 拆分为 compile-/release-/deploy-{client,site,server}.sh,抽出公共函数
lib-forgejo.sh;compile-{macos,android,ios,windows}.sh 改去 client-v 前缀;
manual.yml 按前缀路由回滚。
跨流水线解耦:version.yaml 归 client,后端每请求实时读取(不重启、不触发
server 流水线);官网下载页的版本徽章/下载链接/更新日志时间线运行时经
/api/v1/public/release 动态拉取(API 不可达回退构建时静态内容)。为此一次性
扩展后端 changelog 字段(version.go/public.go)与 download.njk 动态渲染。
CHANGELOG.md 重命名为 CHANGELOG-client.md,新增 CHANGELOG-site/server.md;
重写 /release 命令为 /release <part> [version];同步更新 CLAUDE.md 与部署文档。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
92 lines
2.5 KiB
Go
92 lines
2.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type versionConfig struct {
|
|
Version string `yaml:"version"`
|
|
BuildNumber int `yaml:"build_number"`
|
|
ForceUpdate bool `yaml:"force_update"`
|
|
ReleaseNotes string `yaml:"release_notes"`
|
|
DownloadURLs map[string]string `yaml:"download_urls"`
|
|
// Changelog 由 client 发版脚本从 CHANGELOG-client.md 写入(最近 3 条),
|
|
// 供官网下载页运行时拉取渲染更新日志,无需重建官网。
|
|
Changelog []changelogEntry `yaml:"changelog"`
|
|
}
|
|
|
|
type changelogEntry struct {
|
|
Version string `yaml:"version" json:"version"`
|
|
Date string `yaml:"date" json:"date"`
|
|
Intro string `yaml:"intro" json:"intro"`
|
|
Sections []changelogSection `yaml:"sections" json:"sections"`
|
|
}
|
|
|
|
type changelogSection struct {
|
|
Type string `yaml:"type" json:"type"`
|
|
Items []string `yaml:"items" json:"items"`
|
|
}
|
|
|
|
// changelogOrEmpty 保证响应里 changelog 始终是数组(而非 null),方便前端遍历。
|
|
func changelogOrEmpty(c []changelogEntry) []changelogEntry {
|
|
if c == nil {
|
|
return []changelogEntry{}
|
|
}
|
|
return c
|
|
}
|
|
|
|
// GetVersion GET /version
|
|
func GetVersion(c *gin.Context) {
|
|
cfg, err := loadVersionConfig()
|
|
if err != nil {
|
|
log.Printf("[version] failed to load version config: %v", err)
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "version config unavailable"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"version": cfg.Version,
|
|
"build_number": cfg.BuildNumber,
|
|
"force_update": cfg.ForceUpdate,
|
|
"release_notes": cfg.ReleaseNotes,
|
|
"download_urls": cfg.DownloadURLs,
|
|
"changelog": changelogOrEmpty(cfg.Changelog),
|
|
})
|
|
}
|
|
|
|
func loadVersionConfig() (*versionConfig, error) {
|
|
// 查找 config/version.yaml,相对于可执行文件或源码目录
|
|
candidates := []string{
|
|
"config/version.yaml",
|
|
filepath.Join(sourceDir(), "config/version.yaml"),
|
|
}
|
|
for _, path := range candidates {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
var cfg versionConfig
|
|
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
return &cfg, nil
|
|
}
|
|
return nil, os.ErrNotExist
|
|
}
|
|
|
|
// sourceDir 返回当前源文件所在目录的上两级(backend 根目录)
|
|
func sourceDir() string {
|
|
_, filename, _, ok := runtime.Caller(0)
|
|
if !ok {
|
|
return "."
|
|
}
|
|
// handler/ → internal/ → backend/
|
|
return filepath.Join(filepath.Dir(filename), "..", "..")
|
|
}
|