diff --git a/.github/aw/compat.json b/.github/aw/compat.json index 0ea0160b78a..0cc6b903db3 100644 --- a/.github/aw/compat.json +++ b/.github/aw/compat.json @@ -10,7 +10,7 @@ "min-gh-aw": "0.72.0", "max-gh-aw": "*", "min-agent": "1.0.21", - "max-agent": "1.0.56", + "max-agent": "1.0.75", "open": true }, { diff --git a/Makefile b/Makefile index e962bbd1c13..2b792d76db5 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ all: build # Build the binary, run make deps before this .PHONY: build -build: sync-action-pins sync-action-scripts +build: sync-action-pins sync-action-scripts sync-compat go build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/gh-aw # Build for all platforms @@ -1105,6 +1105,16 @@ sync-action-scripts: @cp install-gh-aw.ps1 actions/setup-cli/install.ps1 @echo "✓ Action scripts synced successfully" +# Sync max-agent in the latest compat.json interval with DefaultCopilotVersion +.PHONY: sync-compat +sync-compat: + @bash scripts/sync-compat.sh + +# Check that compat.json is in sync with DefaultCopilotVersion (CI gate) +.PHONY: check-stale-compat +check-stale-compat: + @bash scripts/sync-compat.sh --check + # Sync install-gh-aw.sh SHA/hash constants in pkg/cli/copilot_setup.go .PHONY: sync-install-script-hashes sync-install-script-hashes: @@ -1301,6 +1311,8 @@ help: @echo " install - Install binary locally" @echo " sync-action-pins - Sync actions-lock.json from .github/aw to pkg/actionpins/data and pkg/workflow/data (runs automatically during build)" @echo " sync-action-scripts - Sync install-gh-aw.sh and install-gh-aw.ps1 to actions/setup-cli/ (runs automatically during build)" + @echo " sync-compat - Sync max-agent in .github/aw/compat.json latest interval with DefaultCopilotVersion (runs automatically during build)" + @echo " check-stale-compat - Guard: detect when compat.json max-agent is out of sync with DefaultCopilotVersion" @echo " sync-install-script-hashes - Update install-gh-aw.sh SHA and SHA256 constants in pkg/cli/copilot_setup.go (runs automatically during update)" @echo " update - Update GitHub Actions and workflows, sync action pins, and rebuild binary" @echo " fix - Apply automatic codemod-style fixes to workflow files (depends on build)" diff --git a/scripts/sync-compat.sh b/scripts/sync-compat.sh new file mode 100755 index 00000000000..0c2d4ba5004 --- /dev/null +++ b/scripts/sync-compat.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# sync-compat.sh - Keep .github/aw/compat.json in sync with DefaultCopilotVersion +# +# Reads DefaultCopilotVersion from pkg/constants/version_constants.go and updates +# the max-agent field of the latest interval (the entry with "open": true) in +# .github/aw/compat.json. +# +# Usage: +# sync-compat.sh [--check] +# +# Options: +# --check Exit with code 1 if compat.json is out of sync instead of updating it. +# +# Exit codes: +# 0 - compat.json is already in sync, or was updated successfully +# 1 - compat.json is out of sync (only when --check is passed), or an error occurred + +set -euo pipefail + +# Script must be run from the repository root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +CONSTANTS_FILE="$REPO_ROOT/pkg/constants/version_constants.go" +COMPAT_FILE="$REPO_ROOT/.github/aw/compat.json" + +CHECK_ONLY=0 +for arg in "$@"; do + if [ "$arg" = "--check" ]; then + CHECK_ONLY=1 + fi +done + +# Extract DefaultCopilotVersion from Go constants file +COPILOT_VERSION=$(grep -oP '^\s*const DefaultCopilotVersion\s+Version\s*=\s*"\K[^"]+' "$CONSTANTS_FILE") +if [ -z "$COPILOT_VERSION" ]; then + echo "Error: could not extract DefaultCopilotVersion from $CONSTANTS_FILE" >&2 + exit 1 +fi + +# Read the current max-agent of the latest interval (entry with "open": true) +CURRENT_MAX_AGENT=$(jq -r '."agent-compat-v1".copilot[] | select(.open == true) | ."max-agent"' "$COMPAT_FILE") +if [ -z "$CURRENT_MAX_AGENT" ] || [ "$CURRENT_MAX_AGENT" = "null" ]; then + echo "Error: could not find latest interval (\"open\": true) in $COMPAT_FILE" >&2 + exit 1 +fi + +if [ "$CURRENT_MAX_AGENT" = "$COPILOT_VERSION" ]; then + echo "compat.json is already in sync (max-agent=$COPILOT_VERSION)" + exit 0 +fi + +if [ "$CHECK_ONLY" = "1" ]; then + echo "Error: compat.json is out of sync: max-agent=$CURRENT_MAX_AGENT, DefaultCopilotVersion=$COPILOT_VERSION" >&2 + echo "Run 'make sync-compat' to update." >&2 + exit 1 +fi + +# Update max-agent in the latest interval +UPDATED=$(jq --arg version "$COPILOT_VERSION" \ + '."agent-compat-v1".copilot = [."agent-compat-v1".copilot[] | if .open == true then ."max-agent" = $version else . end]' \ + "$COMPAT_FILE") + +echo "$UPDATED" > "$COMPAT_FILE" +echo "Updated compat.json: max-agent $CURRENT_MAX_AGENT -> $COPILOT_VERSION"