#!/usr/bin/env bash # bump-build-version.sh — git pre-commit hook. # # Auto-increments the minor of BUILD_REDBEAR_VERSION in # local/scripts/build-redbear.sh whenever that file is part of the commit. # The version starts at 1.0 and bumps to 1.1, 1.2, … on every committed change, # so the version printed at build start always reflects how many times the # orchestrator has changed. No manual editing of the minor is needed. # # Installed via: ./local/scripts/install-git-hooks.sh --all # Bypass a single commit with: git commit --no-verify # # Limitation: re-staging happens at whole-file granularity, so a partial # (`git add -p`) stage of build-redbear.sh will be promoted to the full file. # That is the standard trade-off for a re-staging pre-commit hook. set -euo pipefail REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0 FILE="local/scripts/build-redbear.sh" # Only act if the build script is actually staged for this commit. if ! git diff --cached --name-only -- "$FILE" | grep -qx "$FILE"; then exit 0 fi # Read the version from the STAGED content (what will actually be committed). cur="$(git show ":$FILE" 2>/dev/null \ | grep -m1 -oE 'BUILD_REDBEAR_VERSION="[0-9]+\.[0-9]+"' \ | grep -oE '[0-9]+\.[0-9]+' || true)" if [ -z "$cur" ]; then # Version constant not found (unexpected) — do not block the commit. exit 0 fi major="${cur%%.*}" minor="${cur#*.}" new="${major}.$((minor + 1))" # Update the working-tree file and re-stage so the commit records the bump. sed -i -E "s/^BUILD_REDBEAR_VERSION=\"[0-9]+\.[0-9]+\"/BUILD_REDBEAR_VERSION=\"${new}\"/" \ "$REPO_ROOT/$FILE" git add "$FILE" echo "bump-build-version: build-redbear.sh ${cur} -> ${new}" exit 0