beads/scripts/check-versions/main.go
Julian Knutsen 555b01d789
fix(release): name the version-drift remedies that work (#7083)
Post-merge review follow-up to #5614.

#5614 replaced the shell checker's three-way drift remedy with a bare
"Run: scripts/update-versions.sh <canonical>" in both the Go checker
(status 1) and bd preflight's Version sync output, and the release-tag
pre-push hook kept answering status 1 with "Fix with:
scripts/update-versions.sh <version>". update-versions.sh derives the old
version from cmd/bd/version.go and anchors its substitutions on it, so
with version.go already at the canonical version that re-run rewrites
only the .githooks markers and uv.lock and leaves any other drifted file
as it was.

Restore the remedy as versioncheck.Report.MismatchRemedy, shared by the
checker and preflight:
- one file drifted: edit it to the expected value
- several drifted: set version.go to the previous version, then replay
  scripts/update-versions.sh <canonical>
- version.go is wrong: scripts/update-versions.sh <intended-version>

The hook's status-1 text now points at the checker output instead of
prescribing update-versions.sh; status 3 is unchanged. The text is sized
so one drifted file shows in full within preflight's 500-byte human
output, with the several-files case ahead of the version.go one.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 11:34:06 -07:00

154 lines
3.8 KiB
Go

// check-versions validates every released Beads version surface through the
// same Go authority used by bd preflight.
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/steveyegge/beads/internal/versioncheck"
)
func main() {
os.Exit(run(os.Args[1:], ".", os.Stdout, os.Stderr, versioncheck.CheckUVLockFreshness))
}
const (
red = "\033[0;31m"
green = "\033[0;32m"
reset = "\033[0m"
)
type expectedVersionValue struct {
value string
specified bool
}
func (value *expectedVersionValue) String() string {
return value.value
}
func (value *expectedVersionValue) Set(candidate string) error {
if value.specified {
return fmt.Errorf("--expect may be specified only once")
}
value.specified = true
if candidate == "" {
return fmt.Errorf("--expect requires a non-empty VERSION")
}
value.value = candidate
return nil
}
func run(
args []string,
start string,
stdout, stderr io.Writer,
checkUVLock versioncheck.UVLockChecker,
) int {
flags := flag.NewFlagSet("check-versions", flag.ContinueOnError)
flags.SetOutput(stderr)
var expected expectedVersionValue
flags.Var(
&expected,
"expect",
"require the canonical release version to equal this exact value",
)
if err := flags.Parse(args); err != nil {
return 2
}
if flags.NArg() != 0 {
fmt.Fprintln(stderr, "usage: scripts/check-versions.sh [--expect VERSION]")
return 2
}
root, found, err := versioncheck.FindRoot(start)
if err != nil {
fmt.Fprintf(stderr, "Cannot identify Beads release root: %v\n", err)
return 1
}
if !found {
fmt.Fprintln(stderr, "Cannot identify a Beads source repository from the current directory")
return 1
}
report, err := versioncheck.Check(root)
printReport(stdout, report)
if err != nil {
fmt.Fprintf(stderr, "\n%s❌ %v%s\n", red, err, reset)
if report.CanonicalVersion != "" {
fmt.Fprintf(stderr, "\n%s\n", report.MismatchRemedy())
}
return 1
}
if expected.specified && report.CanonicalVersion != expected.value {
fmt.Fprintf(
stderr,
"Canonical release version %s does not match required version %s\n",
report.CanonicalVersion,
expected.value,
)
// Distinct from status 1: the release surfaces agree with each other,
// only the required version differs. Callers such as the release-tag
// pre-push hook must not answer this with the version-drift remedy.
return 3
}
if checkUVLock != nil {
available, checkErr := checkUVLock(root)
if available && checkErr != nil {
fmt.Fprintln(
stderr,
red+"❌ MCP uv.lock: stale — run: uv lock --directory integrations/beads-mcp"+reset,
)
return 1
}
if available {
fmt.Fprintln(stdout, green+"✓ MCP uv.lock: fresh (uv lock --check)"+reset)
}
}
fmt.Fprintf(
stdout,
"\n%s✓ Version files in sync at: %s%s\n",
green,
report.CanonicalVersion,
reset,
)
// The checker reads no documentation surface, so it must not imply one.
fmt.Fprintln(stdout, " (Version files only — this script does not check docs. The docs")
fmt.Fprintln(stdout, " release line and docs/cli-docs.pin are manual release steps; see")
fmt.Fprintln(stdout, " RELEASING.md.)")
return 0
}
func printReport(output io.Writer, report versioncheck.Report) {
if report.CanonicalVersion == "" {
return
}
fmt.Fprintf(output, "Canonical version (from version.go): %s\n\n", report.CanonicalVersion)
for _, item := range report.Sources {
switch {
case item.Problem == "":
fmt.Fprintf(output, "%s✓ %s: %s%s\n", green, item.Description, item.Version, reset)
case item.Version != "":
fmt.Fprintf(
output,
"%s❌ %s: %s (expected %s)%s\n",
red,
item.Description,
item.Version,
item.Expected,
reset,
)
default:
fmt.Fprintf(
output,
"%s❌ %s: %s (expected %s)%s\n",
red,
item.Description,
item.Problem,
item.Expected,
reset,
)
}
}
}