opentmd

企业级版本管理

OpenTMD 采用 SemVer 2.0.0 + Keep a Changelog + 单一版本源(SSOT)。

单一版本源

层 位置 作用
产品版本 仓库根 VERSION 发布与门禁的唯一真相
变更记录 CHANGELOG.md 面向用户的版本说明
运行时 internal/version 二进制注入的 Version/Commit/Date/Channel
Git annotated tag v+VERSION 触发 Release CI

禁止在 internal/tui、internal/daemon 等处硬编码产品版本号。

版本号规则

格式:MAJOR.MINOR.PATCH[-prerelease]

企业兼容窗口:同一 MAJOR 下,运行时与目标最多相差 1 个 MINOR(version.Compatible)。

发布通道(Channel)

通道 说明 选择方式
stable 正式版(默认) tag 无预发布后缀;OPENTMD_CHANNEL=stable
beta 预发布 tag 含 beta/rc/alpha;--channel beta
nightly 每日构建 tag 含 nightly
dev 本地开发构建 未注入或 Version=dev
opentmd upgrade --check
opentmd upgrade --channel beta
OPENTMD_CHANNEL=beta opentmd upgrade

日常发布流程

# 1. 抬版本并归档 CHANGELOG Unreleased
./scripts/release.sh bump patch    # 或 minor / major / 0.2.0

# 2. 人工确认 CHANGELOG,提交
git add VERSION CHANGELOG.md
git commit -m "release: v$(tr -d '[:space:]' < VERSION)"

# 3. 打 annotated tag(不自动 push)
./scripts/release.sh tag
git push origin HEAD
git push origin "v$(tr -d '[:space:]' < VERSION)"

推送 v* tag 后,.github/workflows/release.yml 会:

  1. 校验 tag 与 VERSION 一致(check-version.sh)
  2. 交叉编译并注入 internal/version.*
  3. 创建 GitHub Release + 发布 npm

门禁

./scripts/check-version.sh          # 本地 / CI
./scripts/build.sh --test           # 含 version gate
./scripts/build.sh --release        # 发布包前再次校验

构建注入

-X github.com/opentmd/opentmd-cli/internal/version.Version=0.1.0
-X github.com/opentmd/opentmd-cli/internal/version.Commit=<sha>
-X github.com/opentmd/opentmd-cli/internal/version.Date=<RFC3339>
-X github.com/opentmd/opentmd-cli/internal/version.Channel=stable

opentmd --version 输出形如:0.1.0+abc1234 (2026-11-28T…).