mcp/workflow-scripts-v2/version
Lilith eefccd19b9 ci: add Forgejo Actions publish workflows to all packages
Added standardized workflows for automated publishing on push to main/master.
Configuration-driven, version-checked, workspace-aware workflows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 11:41:53 -08:00

119 lines
3.3 KiB
Bash
Executable file

#!/bin/bash
# Unified version management
# Usage: ./workflow/version [command]
# (no args) - Show current version
# major - Bump major version, reset counters
# merge - Increment merge counter (called by finish)
# build - Increment build counter (called by CI)
# sync - Sync version to all package.json files
set -e
VERSION_FILE="codebase/VERSION.json"
if [[ ! -f "$VERSION_FILE" ]]; then
echo "Error: $VERSION_FILE not found"
exit 1
fi
# Read current values
read_version() {
MAJOR=$(jq -r '.major' "$VERSION_FILE")
MERGES=$(jq -r '.merges' "$VERSION_FILE")
BUILDS=$(jq -r '.builds' "$VERSION_FILE")
VERSION="$MAJOR.$MERGES.$BUILDS"
}
# Write updated values
write_version() {
local last_merge="$1"
local last_build="$2"
jq --arg v "$VERSION" \
--argjson major "$MAJOR" \
--argjson merges "$MERGES" \
--argjson builds "$BUILDS" \
--arg lastMerge "$last_merge" \
--arg lastBuild "$last_build" \
'.major = $major | .merges = $merges | .builds = $builds | .version = $v |
if $lastMerge != "" then .lastMerge = $lastMerge else . end |
if $lastBuild != "" then .lastBuild = $lastBuild else . end' \
"$VERSION_FILE" > "$VERSION_FILE.tmp" && mv "$VERSION_FILE.tmp" "$VERSION_FILE"
}
# Sync to all package.json files
sync_packages() {
echo "Syncing version $VERSION to all packages..."
find . -name "package.json" -not -path "*/node_modules/*" | while read -r pkg; do
# Update version field
jq --arg v "$VERSION" '.version = $v' "$pkg" > "$pkg.tmp" && mv "$pkg.tmp" "$pkg"
echo " Updated: $pkg"
done
echo "Done. $VERSION synced to all packages."
}
read_version
case "${1:-}" in
"")
echo "$VERSION"
;;
"show"|"status")
echo "Version: $VERSION"
echo ""
echo " Major: $MAJOR"
echo " Merges: $MERGES"
echo " Builds: $BUILDS"
echo ""
jq -r 'if .lastMerge then "Last merge: \(.lastMerge)" else empty end' "$VERSION_FILE"
jq -r 'if .lastBuild then "Last build: \(.lastBuild)" else empty end' "$VERSION_FILE"
;;
"major")
echo "Current: $VERSION"
((MAJOR++))
MERGES=0
BUILDS=0
VERSION="$MAJOR.$MERGES.$BUILDS"
write_version "" ""
echo "New: $VERSION"
echo ""
echo "Major version bumped. Counters reset."
echo "Consider: git tag v$VERSION"
;;
"merge")
WORKTREE_NAME="${2:-unknown}"
((MERGES++))
VERSION="$MAJOR.$MERGES.$BUILDS"
write_version "$WORKTREE_NAME" ""
echo "$VERSION"
;;
"build")
((BUILDS++))
VERSION="$MAJOR.$MERGES.$BUILDS"
write_version "" "$(date -Iseconds)"
echo "$VERSION"
;;
"sync")
sync_packages
;;
*)
echo "Usage: ./workflow/version [command]"
echo ""
echo "Commands:"
echo " (no args) Show current version"
echo " show Show version details"
echo " major Bump major version, reset counters"
echo " merge Increment merge counter"
echo " build Increment build counter"
echo " sync Sync to all package.json files"
exit 1
;;
esac