beads/scripts/update-versions.sh
matt wilkie 801fb95d17
ci(release): guard against version/docs drift on release (#4247)
Root cause of the 1.0.5 incident: the beads-release formula's snapshot-docs
step is advisory prose, not enforced. A release can bump cmd/bd/version.go and
tag/push while skipping the Docusaurus snapshot, and nothing blocks publish, so
the drift only surfaces as a red main after artifacts ship.

Three layered guards:

A. Atomic bump — scripts/snapshot-release-docs.sh encapsulates the docs
   snapshot (docusaurus docs:version + lastVersion + regenerate CLI/llms +
   verify) as one idempotent unit. scripts/update-versions.sh now calls it so
   version.go and the docs snapshot cannot diverge (escape hatch: --skip-docs).
   The formula's snapshot-docs step now invokes the same script.

B. Pre-publish gate — release.yml gains a verify-version-consistency job that
   checks the tag matches version.go and runs check-versions.sh. goreleaser
   (and thus all downstream publish jobs) needs it; publish-pypi keeps its
   always() decoupling from goreleaser but is hard-gated on the verify result.
   Drift now blocks publish instead of redding main afterward.

C. Pre-push refusal — .githooks/pre-push runs check-versions.sh when a
   refs/tags/v* tag is pushed and refuses on drift, catching it on the
   developer's machine before CI. Installed via the existing core.hooksPath.

Verified: shellcheck clean; release.yml valid YAML; script guard paths and the
hook's branch/tag dispatch tested.

Refs: mybd-a5hn

Agent-Signature: claude-opus-4-8-medium on behalf of matt wilkie
2026-05-28 21:52:10 -07:00

155 lines
5.7 KiB
Bash
Executable file

#!/bin/bash
set -e
# =============================================================================
# Quick version bump utility (no git operations)
# =============================================================================
#
# Updates version numbers across all beads components without any git
# operations. Use this for local testing or when you want manual control
# over commits.
#
# For full releases with CI gates and verification, use:
# bd mol wisp beads-release --var version=X.Y.Z
#
# =============================================================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
usage() {
echo "Usage: $0 <version> [--skip-docs]"
echo ""
echo "Updates version numbers across all components (no git operations),"
echo "and snapshots the Docusaurus release docs so version.go and the docs"
echo "snapshot cannot drift apart."
echo ""
echo " --skip-docs Skip the Docusaurus snapshot (e.g. on a host without"
echo " Node.js). You must then run scripts/snapshot-release-docs.sh"
echo " <version> elsewhere before tagging, or CI will fail."
echo ""
echo "Example: $0 0.47.1"
echo ""
echo "For full releases, use: bd mol wisp beads-release --var version=X.Y.Z"
}
NEW_VERSION=""
SKIP_DOCS=0
for arg in "$@"; do
case "$arg" in
--skip-docs) SKIP_DOCS=1 ;;
-h|--help) usage; exit 0 ;;
-*) echo "Unknown option: $arg" >&2; usage; exit 1 ;;
*)
if [ -n "$NEW_VERSION" ]; then
echo "Error: multiple versions given" >&2; usage; exit 1
fi
NEW_VERSION="$arg"
;;
esac
done
if [ -z "$NEW_VERSION" ]; then
usage
exit 1
fi
# Validate semantic versioning
if ! [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${RED}Error: Invalid version format '$NEW_VERSION'${NC}"
echo "Expected: MAJOR.MINOR.PATCH (e.g., 0.47.1)"
exit 1
fi
# Check we're in repo root
if [ ! -f "cmd/bd/version.go" ]; then
echo -e "${RED}Error: Must run from repository root${NC}"
exit 1
fi
# Get current version
CURRENT_VERSION=$(grep 'Version = ' cmd/bd/version.go | sed 's/.*"\(.*\)".*/\1/')
echo -e "${YELLOW}Bumping: $CURRENT_VERSION → $NEW_VERSION${NC}"
echo ""
# Cross-platform sed helper
update_file() {
local file=$1
local old=$2
local new=$3
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s|$old|$new|g" "$file"
else
sed -i "s|$old|$new|g" "$file"
fi
}
echo "Updating version files..."
# 1. cmd/bd/version.go
echo " • cmd/bd/version.go"
update_file "cmd/bd/version.go" "Version = \"$CURRENT_VERSION\"" "Version = \"$NEW_VERSION\""
# 2. Plugin JSON files
echo " • plugin metadata"
update_file "plugins/beads/.claude-plugin/plugin.json" "\"version\": \"$CURRENT_VERSION\"" "\"version\": \"$NEW_VERSION\""
update_file "plugins/beads/.codex-plugin/plugin.json" "\"version\": \"$CURRENT_VERSION\"" "\"version\": \"$NEW_VERSION\""
update_file "plugins/beads/.copilot-plugin/plugin.json" "\"version\": \"$CURRENT_VERSION\"" "\"version\": \"$NEW_VERSION\""
update_file ".claude-plugin/marketplace.json" "\"version\": \"$CURRENT_VERSION\"" "\"version\": \"$NEW_VERSION\""
# 3. MCP Python package
echo " • integrations/beads-mcp/*"
update_file "integrations/beads-mcp/pyproject.toml" "version = \"$CURRENT_VERSION\"" "version = \"$NEW_VERSION\""
update_file "integrations/beads-mcp/src/beads_mcp/__init__.py" "__version__ = \"$CURRENT_VERSION\"" "__version__ = \"$NEW_VERSION\""
# 4. npm package
echo " • npm-package/package.json"
update_file "npm-package/package.json" "\"version\": \"$CURRENT_VERSION\"" "\"version\": \"$NEW_VERSION\""
# 5. README badge
echo " • README.md"
update_file "README.md" "Alpha (v$CURRENT_VERSION)" "Alpha (v$NEW_VERSION)"
# 6. default.nix
echo " • default.nix"
update_file "default.nix" "version = \"$CURRENT_VERSION\";" "version = \"$NEW_VERSION\";"
# 7. Hook templates — now generated dynamically by cmd/bd/hooks.go using the
# Version constant from version.go. No template files to update.
# (Previously updated cmd/bd/templates/hooks/* which no longer exist.)
# 8. Windows PE resource metadata
echo " • cmd/bd/winres/winres.json"
update_file "cmd/bd/winres/winres.json" "\"file_version\": \"$CURRENT_VERSION\"" "\"file_version\": \"$NEW_VERSION\""
update_file "cmd/bd/winres/winres.json" "\"product_version\": \"$CURRENT_VERSION\"" "\"product_version\": \"$NEW_VERSION\""
update_file "cmd/bd/winres/winres.json" "\"FileVersion\": \"$CURRENT_VERSION\"" "\"FileVersion\": \"$NEW_VERSION\""
update_file "cmd/bd/winres/winres.json" "\"ProductVersion\": \"$CURRENT_VERSION\"" "\"ProductVersion\": \"$NEW_VERSION\""
echo " • cmd/bd/winres/manifest.xml"
update_file "cmd/bd/winres/manifest.xml" "version=\"$CURRENT_VERSION.0\"" "version=\"$NEW_VERSION.0\""
echo ""
echo -e "${GREEN}✓ Version constants updated to $NEW_VERSION${NC}"
echo ""
# Snapshot the Docusaurus release docs as part of the same bump so version.go
# and the published docs cannot diverge. This is the failure mode that left
# main red after the 1.0.5 release (version bumped, docs snapshot missing).
if [ "$SKIP_DOCS" -eq 1 ]; then
echo -e "${YELLOW}Skipping docs snapshot (--skip-docs).${NC}"
echo " Run scripts/snapshot-release-docs.sh $NEW_VERSION before tagging,"
echo " or CI (check-version-consistency) will fail."
else
echo "Snapshotting release docs..."
./scripts/snapshot-release-docs.sh "$NEW_VERSION"
fi
echo ""
echo "Changed files:"
git diff --stat 2>/dev/null || true
echo ""
echo "Next steps:"
echo " • Update CHANGELOG.md with release notes"
echo " • Update cmd/bd/info.go versionChanges"
echo " • Or use: bd mol wisp beads-release --var version=$NEW_VERSION"