-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmerge-reference-impl-start.sh
More file actions
executable file
·88 lines (77 loc) · 4.08 KB
/
merge-reference-impl-start.sh
File metadata and controls
executable file
·88 lines (77 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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" <<EOF
# Auto-generated by merge-reference-impl-start.sh – do not commit
BRANCH_NAME=$BRANCH_NAME
REFERENCE_IMPL_DIR=$REFERENCE_IMPL_DIR
LAST_MERGE_COMMIT=$LAST_MERGE_COMMIT
CLI_VERSION=$CLI_VERSION
EOF
echo "▸ Env file written to $ENV_FILE (sourced by other merge scripts)."
echo ""
echo "✅ Ready. Next steps:"
echo " 1. Run ./.github/scripts/reference-impl-sync/merge-reference-impl-diff.sh to see the full diff analysis."
echo " 2. Port changes to the Java SDK."
echo " 3. Run ./.github/scripts/reference-impl-sync/merge-reference-impl-finish.sh when done."