Skip to content

chore(build): document RELEASE_TAG and warn on an untraceable version - #654

Merged
xiaods merged 1 commit into
mainfrom
chore/release-tag-evaluation
Oct 19, 2026
Merged

xiaods merged 1 commit into
mainfrom
chore/release-tag-evaluation

Conversation

@xiaods

@xiaods xiaods commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

结论:RELEASE_TAG 有意义,但目前在仓库内是死配置

它只被 hack/version.sh:7 一行读取,仓库里没有任何地方设置它,也没有任何文档提到它。我把脚本的三条路径都实测了一遍:

版本解析顺序:RELEASE_TAG → git tag -l --contains HEAD → $VERSION_K8S+k8e-<commit8>

场景 是否需要 RELEASE_TAG 实测结果
仓库内 CI(release.yml) 否 shallow clone 也能拿到 v1.37.0-20261018-rc1
拷贝的源码树(无 .git)+ 未设 RELEASE_TAG — ⚠️ VERSION=v1.37.0+k8e-,commit 为空
拷贝的源码树 + 设了 RELEASE_TAG 是 ✅ VERSION=v1.37.0-rc9

仓库内 CI 不需要它:release.yml 用默认的 shallow actions/checkout,而 GitHub 仍会拉取指向被检出 commit 的 tag。我用 --depth 1 真实克隆验证过,当前 merge commit 解析为 v1.37.0-20261018-rc1。

只有一种场景真正需要它:构建一个拷贝出来的源码树(发布 tarball、vendored/air-gap 构建、没有 .git 的 Docker context)。此时 if [ -d .git ] 会整段跳过 tag 查找,版本退化成 v1.37.0+k8e-——commit 为空、末位一个连字符,+ 换成 - 之后变成 v1.37.0-k8e-,两处都非法。仓库内没有任何 Dockerfile 自己编译二进制(都是 COPY bin/),所以这个问题一直没暴露。

也就是说:这个变量是有价值的,但对当前仓库的所有工作流都是死代码——它服务于本仓库没有执行的那些打包方式。

改动

  1. 在赋值处补文档——说明用途、何时该设置、不设置会怎样。

  2. 拿不到 tag 也拿不到 commit 时,向 stderr 报警(原先是静默产出 v1.37.0+k8e-)。只报警不改退出码,因为 build.zig 的 getVersionEnv 解析的是 stdout,我验证过 stdout 保持干净、VERSION/VERSION_TAG/COMMIT 不受影响。

  3. 给赋值加引号——纯粹是卫生习惯,不是修 bug:bash 不会对赋值语句右侧做 word splitting,"$RELEASE_TAG" 和 $RELEASE_TAG 赋值结果完全一致(已实测)。注释里写明了这一点,免得把错误结论传下去。

验证

# 仓库路径(有 tag)
VERSION=[v1.37.0-20261018-rc1]  无报警

# 无 .git、无 RELEASE_TAG
VERSION=[v1.37.0+k8e-]          warning × 2

# 无 .git、有 RELEASE_TAG
VERSION=[v1.37.0-rc9]           无报警

另外:source hack/version.sh 的 stdout 不含 warning(不会污染 build.zig 解析);zig build sandboxd 与 Go 测试通过;zig build k8e 在本机报 ld: library 'crt0.o' not found——main 上一模一样(本机缺 Xcode CLT,与本次改动无关)。

顺带发现

PR #653 已合并,release tag v1.37.0-20261018-rc1 就打在 merge commit 上——这也是上面第 1 条结论的直接证据。

RELEASE_TAG is read by exactly one line of hack/version.sh, is set by nothing
in this repository, and is undocumented anywhere. This records what it is
actually for, based on testing the three paths through the script.

Evaluation
----------
The version is resolved in this order: RELEASE_TAG, then `git tag -l --contains
HEAD`, then "$VERSION_K8S+k8e-<commit8>".

- In-repo CI needs RELEASE_TAG for nothing. release.yml builds with the
  default shallow `actions/checkout`, which still fetches tags pointing at the
  checked-out commit; a `--depth 1` clone of this repo resolves the current
  merge to `v1.37.0-20261018-rc1`. Verified against a real shallow clone.

- Building a copied source tree needs it, and this is the only case that
  exercises it. With no `.git` the tag lookup is skipped by the `if [ -d .git ]`
  guard, so the version degrades to `v1.37.0+k8e-`: empty commit, trailing
  dash, and `v1.37.0-k8e-` once '+' is rewritten for an image tag — invalid in
  both places. No in-repo Dockerfile builds the binaries (they all COPY from
  bin/), which is why this has never surfaced.

So the variable is meaningful but currently dead: it exists for release
tarballs and vendored/air-gapped builds that no workflow in this repo performs.

Changes
-------
- Document what it is for and when to set it, above the assignment.

- Warn on stderr when neither a tag nor a commit is available, so a
  `v1.37.0+k8e-` build announces itself instead of shipping quietly. Warnings
  only: the script's stdout is what build.zig's getVersionEnv parses for
  VERSION, and it stays clean (checked).

- Quote the assignment. Hygiene only — bash does not word-split an
  assignment's right-hand side, so "$RELEASE_TAG" and $RELEASE_TAG already
  assign identically. An earlier claim that this fixed a splitting bug was
  wrong; the comment says so rather than repeating it.

Verified: the repo path still resolves to v1.37.0-20261018-rc1, the no-.git path
warns with VERSION=v1.37.0+k8e-, and RELEASE_TAG=v1.37.0-rc9 resolves cleanly
with no warning. `zig build sandboxd` and the Go suites pass; `zig build k8e`
fails with `ld: library 'crt0.o' not found` identically on main (missing Xcode
CLT on this host, unrelated).
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

977 tests  ±0   950 ✅ ±0   6m 48s ⏱️ -6s
120 suites ±0    27 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 1b67bbc. ± Comparison against base commit 721c0c5.

@xiaods
xiaods merged commit 51ed878 into main Oct 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant