#!/usr/bin/env bash # ────────────────────────────────────────────────────────────── # merge-reference-impl-start.sh # # Prepares the workspace for a reference implementation merge: # 1. Creates a dated branch from main # 2. Updates Copilot CLI and records the new version # 3. Clones the reference implementation copilot-sdk repo into a temp dir # 4. Reads .lastmerge and prints a short summary of new commits # # Usage: ./.github/scripts/reference-impl-sync/merge-reference-impl-start.sh # Output: Exports REFERENCE_IMPL_DIR and LAST_MERGE_COMMIT to a # .merge-env file so other scripts can source it. # ────────────────────────────────────────────────────────────── set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)" cd "$ROOT_DIR" REFERENCE_IMPL_REPO="https://github.com/github/copilot-sdk.git" ENV_FILE="$ROOT_DIR/.merge-env" # ── 1. Create branch (or reuse existing) ───────────────────── CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) if [[ "$CURRENT_BRANCH" != "main" ]]; then # Already on a non-main branch (e.g., coding agent's auto-created PR branch). # Stay on this branch — do not create a new one. BRANCH_NAME="$CURRENT_BRANCH" echo "▸ Already on branch '$BRANCH_NAME' — reusing it (coding agent mode)." git pull origin main --no-edit 2>/dev/null || echo " (pull from main skipped or fast-forward not possible)" else echo "▸ Ensuring main is up to date…" git pull origin main BRANCH_NAME="merge-reference-impl-$(date +%Y%m%d)" echo "▸ Creating branch: $BRANCH_NAME" git checkout -b "$BRANCH_NAME" fi # ── 2. Update Copilot CLI ──────────────────────────────────── echo "▸ Updating Copilot CLI…" if command -v copilot &>/dev/null; then copilot update || echo " (copilot update returned non-zero – check manually)" CLI_VERSION=$(copilot --version | head -n 1 | awk '{print $NF}') echo " Copilot CLI version: $CLI_VERSION" else echo " ⚠ 'copilot' command not found – skipping CLI update." CLI_VERSION="UNKNOWN" fi # ── 3. Clone reference implementation ──────────────────────────────────────── TEMP_DIR=$(mktemp -d) REFERENCE_IMPL_DIR="$TEMP_DIR/copilot-sdk" echo "▸ Cloning reference implementation into $REFERENCE_IMPL_DIR …" git clone --depth=200 "$REFERENCE_IMPL_REPO" "$REFERENCE_IMPL_DIR" # ── 4. Read last merge commit ──────────────────────────────── if [[ ! -f "$ROOT_DIR/.lastmerge" ]]; then echo "❌ .lastmerge file not found in repo root." exit 1 fi LAST_MERGE_COMMIT=$(tr -d '[:space:]' < "$ROOT_DIR/.lastmerge") echo "▸ Last merged reference implementation commit: $LAST_MERGE_COMMIT" # Quick summary echo "" echo "── Reference implementation commits since last merge ──" (cd "$REFERENCE_IMPL_DIR" && git fetch origin main && \ git log --oneline "$LAST_MERGE_COMMIT"..origin/main) || \ echo " (could not generate log – the commit may have been rebased)" echo "" # ── 5. Write env file for other scripts ────────────────────── cat > "$ENV_FILE" <