#!/bin/bash # # Version Bumping Library - Lilith Platform Versioning # # Format: .. # - major: Manual increment for breaking changes # - merges: Incremented by workflow/finish on worktree merge # - builds: Incremented by release-deploy.sh before sync to releases # # Source of truth: codebase/VERSION.json (single version for entire platform) # set -e set -u # Find VERSION.json - always at codebase root find_version_file() { local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" local CODEBASE_ROOT="$(cd "$SCRIPT_DIR/../../../codebase" && pwd)" echo "$CODEBASE_ROOT/VERSION.json" } VERSION_FILE="$(find_version_file)" get_last_version() { if [ -f "$VERSION_FILE" ]; then jq -r '.version' "$VERSION_FILE" else echo "0.0.0" fi } read_version_json() { if [ -f "$VERSION_FILE" ]; then cat "$VERSION_FILE" else echo '{"major": 0, "merges": 0, "builds": 0, "version": "0.0.0"}' fi } # Increment builds counter (called before sync to releases) increment_builds() { local JSON=$(read_version_json) local MAJOR=$(echo "$JSON" | jq -r '.major') local MERGES=$(echo "$JSON" | jq -r '.merges') local BUILDS=$(echo "$JSON" | jq -r '.builds') BUILDS=$((BUILDS + 1)) local NEW_VERSION="$MAJOR.$MERGES.$BUILDS" jq --arg v "$NEW_VERSION" \ --argjson builds "$BUILDS" \ --arg lastBuild "$(date -Iseconds)" \ '.builds = $builds | .version = $v | .lastBuild = $lastBuild' \ "$VERSION_FILE" > "$VERSION_FILE.tmp" && mv "$VERSION_FILE.tmp" "$VERSION_FILE" echo "$NEW_VERSION" } # Increment merges counter (called by workflow/finish) increment_merges() { local WORKTREE_NAME="${1:-unknown}" local JSON=$(read_version_json) local MAJOR=$(echo "$JSON" | jq -r '.major') local MERGES=$(echo "$JSON" | jq -r '.merges') local BUILDS=$(echo "$JSON" | jq -r '.builds') MERGES=$((MERGES + 1)) local NEW_VERSION="$MAJOR.$MERGES.$BUILDS" jq --arg v "$NEW_VERSION" \ --argjson merges "$MERGES" \ --arg lastMerge "$WORKTREE_NAME" \ '.merges = $merges | .version = $v | .lastMerge = $lastMerge' \ "$VERSION_FILE" > "$VERSION_FILE.tmp" && mv "$VERSION_FILE.tmp" "$VERSION_FILE" echo "$NEW_VERSION" } # Bump major version (manual, resets counters) bump_major() { local JSON=$(read_version_json) local MAJOR=$(echo "$JSON" | jq -r '.major') MAJOR=$((MAJOR + 1)) local NEW_VERSION="$MAJOR.0.0" jq --arg v "$NEW_VERSION" \ --argjson major "$MAJOR" \ '.major = $major | .merges = 0 | .builds = 0 | .version = $v' \ "$VERSION_FILE" > "$VERSION_FILE.tmp" && mv "$VERSION_FILE.tmp" "$VERSION_FILE" echo "$NEW_VERSION" } # Legacy compatibility functions determine_bump_type() { # Always return "build" - we use builds counter now echo "build" } bump_version() { local CURRENT="$1" local BUMP_TYPE="$2" # For release process, increment builds increment_builds } create_version_tag() { local NEW_VERSION="$1" local COMMIT_MESSAGE="$2" # Create annotated tag git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION $COMMIT_MESSAGE" echo "v$NEW_VERSION" } get_version_changelog() { local LAST_TAG="$1" local NEW_TAG="$2" cat </dev/null | head -20 | sed 's/^/- /' || echo "- None") Total commits: $(git log ${LAST_TAG}..HEAD --oneline --no-merges 2>/dev/null | wc -l || echo "0") EOF } # Export functions export -f find_version_file export -f get_last_version export -f read_version_json export -f increment_builds export -f increment_merges export -f bump_major export -f determine_bump_type export -f bump_version export -f create_version_tag export -f get_version_changelog