We moved one Go variable and every copy of our new CLI was told to upgrade
说明与用途
在 Go 项目中移动版本变量导致所有发布的二进制文件报告错误的版本并被 API 网关拒绝。修复方法是更新 linker 标志并在签名前验证版本。
问题
A release workflow misconfigured a linker flag, causing all published binaries to report an incorrect version and be rejected by the API gateway.
结果
All published binaries now report the correct semantic version, partners no longer receive false upgrade prompts, and the API gateway accepts valid requests.
工作流
- 1. Update release workflow to use -X internal/buildinfo.version instead of -X main.version.
- 2. Add a pre‑sign check that runs the built binary’s version command and compares output to the git tag.
- 3. Sign and publish the binary only if the check passes.
- 4. Ensure the API gateway parses the version header correctly and does not downgrade unparseable values.
证据
The release workflow builds it with go build and an ldflags option, -X main.version followed by the tag, which tells the Go linker to set the string variable version in package main to that value.
In 2.7.0 a tidy up moved build information out of main into a package of its own, internal/buildinfo, and the variable went with it.
The Go linker does not treat an -X naming a symbol that does not exist as an error, or even a warning. It ignores it.
The release workflow now runs the built binary with its version command and fails unless the output matches the tag, character for character, before anything is signed.
- 记录日期: 2026-11-02T00:43:59.531Z