|
| 1 | +#!/usr/bin/env bash |
| 2 | +# ────────────────────────────────────────────────────────────── |
| 3 | +# sync-codegen-version.sh |
| 4 | +# |
| 5 | +# Updates the @github/copilot dependency in scripts/codegen/package.json |
| 6 | +# to match the version used by the reference implementation. This keeps |
| 7 | +# the code generator schemas in lockstep with the CLI version used for |
| 8 | +# testing, eliminating the gap where Dependabot could race ahead. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# ./sync-codegen-version.sh <reference-impl-dir> |
| 12 | +# |
| 13 | +# Or, when invoked from merge-reference-impl-finish.sh, the directory |
| 14 | +# is passed as $1. |
| 15 | +# ────────────────────────────────────────────────────────────── |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +# Locate the repo root by walking up from this script until we find a pom.xml. |
| 19 | +find_repo_root() { |
| 20 | + local dir |
| 21 | + dir="$(cd "$(dirname "$0")" && pwd)" |
| 22 | + while [[ "$dir" != "/" ]]; do |
| 23 | + if [[ -f "$dir/pom.xml" ]]; then |
| 24 | + echo "$dir" |
| 25 | + return 0 |
| 26 | + fi |
| 27 | + dir="$(dirname "$dir")" |
| 28 | + done |
| 29 | + echo "❌ Could not locate repo root (no pom.xml found above $(dirname "$0"))" >&2 |
| 30 | + return 1 |
| 31 | +} |
| 32 | +ROOT_DIR="$(find_repo_root)" |
| 33 | + |
| 34 | +REFERENCE_IMPL_DIR="${1:-${REFERENCE_IMPL_DIR:-}}" |
| 35 | +if [[ -z "$REFERENCE_IMPL_DIR" ]]; then |
| 36 | + echo "❌ Usage: $0 <reference-impl-dir>" >&2 |
| 37 | + echo " or set REFERENCE_IMPL_DIR in the environment." >&2 |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +PKG_JSON="$REFERENCE_IMPL_DIR/nodejs/package.json" |
| 42 | +if [[ ! -f "$PKG_JSON" ]]; then |
| 43 | + echo "❌ Cannot find $PKG_JSON" >&2 |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +# Extract the @github/copilot version from the reference implementation. |
| 48 | +CLI_VERSION=$(node -e \ |
| 49 | + "const fs=require('fs');const p=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));const v=(p.dependencies&&p.dependencies['@github/copilot'])||(p.devDependencies&&p.devDependencies['@github/copilot']);process.stdout.write(v||'');" \ |
| 50 | + "$PKG_JSON") |
| 51 | + |
| 52 | +if [[ -z "$CLI_VERSION" ]]; then |
| 53 | + echo "❌ Could not extract @github/copilot version from $PKG_JSON" >&2 |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +CODEGEN_DIR="$ROOT_DIR/scripts/codegen" |
| 58 | +CODEGEN_PKG="$CODEGEN_DIR/package.json" |
| 59 | + |
| 60 | +if [[ ! -f "$CODEGEN_PKG" ]]; then |
| 61 | + echo "❌ Cannot find $CODEGEN_PKG" >&2 |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +# Update scripts/codegen/package.json with the new version and regenerate the lock file. |
| 66 | +# Intentionally omit --save-exact to preserve the version specifier used by the reference |
| 67 | +# implementation (e.g. a caret range like '^1.0.36-0' rather than an exact pin '1.0.36-0'). |
| 68 | +echo "▸ Updating scripts/codegen/package.json: @github/copilot → ${CLI_VERSION}" |
| 69 | +cd "$CODEGEN_DIR" |
| 70 | +npm install "@github/copilot@${CLI_VERSION}" |
| 71 | +echo "▸ Updated scripts/codegen to @github/copilot@${CLI_VERSION}" |
0 commit comments