#!/usr/bin/env bash # # Snapshot the Copilot CLI version + per-platform SHA-256 hashes for the # rust crate's bundled-CLI build.rs. Runs at SDK publish time, mirroring # how .NET's _GenerateVersionProps BeforeTargets="Pack" target writes # GitHub.Copilot.SDK.props before NuGet packing. # # Input: # - ../nodejs/package.json - pinned release version. # - The release's SHA256SUMS.txt - per-platform hashes. # # Output: # - cli-version.txt (in the rust crate root). Gitignored. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" RUST_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" REPO_ROOT="$(cd "${RUST_DIR}/.." && pwd)" PACKAGE_FILE="${REPO_ROOT}/nodejs/package.json" OUTPUT="${RUST_DIR}/cli-version.txt" if [[ ! -f "${PACKAGE_FILE}" ]]; then echo "error: ${PACKAGE_FILE} not found" >&2 exit 1 fi VERSION="$(node -e "console.log(require('${PACKAGE_FILE}').copilotCliVersion)")" if [[ -z "${VERSION}" ]]; then echo "error: could not read copilotCliVersion from ${PACKAGE_FILE}" >&2 exit 1 fi CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/download/v${VERSION}/SHA256SUMS.txt" SHA256SUMS="$(curl --fail --silent --show-error --location --retry 3 "${CHECKSUMS_URL}")" ASSETS=( "copilot-darwin-arm64.tar.gz" "copilot-darwin-x64.tar.gz" "copilot-linux-arm64.tar.gz" "copilot-linux-x64.tar.gz" "copilot-linuxmusl-arm64.tar.gz" "copilot-linuxmusl-x64.tar.gz" "copilot-win32-arm64.zip" "copilot-win32-x64.zip" ) TEMP_OUTPUT="${OUTPUT}.tmp.$$" trap 'rm -f "${TEMP_OUTPUT}"' EXIT { echo "# Auto-generated by rust/scripts/snapshot-bundled-cli-version.sh" echo "# Do not edit. Regenerated by the publish workflow on every release." echo "version=${VERSION}" for asset in "${ASSETS[@]}"; do hash="$(printf '%s\n' "${SHA256SUMS}" | awk -v asset="${asset}" '$2 == asset || $2 == "*" asset { print $1; exit }')" if [[ -z "${hash}" ]]; then echo "error: SHA256SUMS.txt does not contain ${asset}" >&2 exit 1 fi echo "${asset}=${hash}" done } > "${TEMP_OUTPUT}" mv "${TEMP_OUTPUT}" "${OUTPUT}" trap - EXIT echo "Wrote ${OUTPUT} (version=${VERSION}, ${#ASSETS[@]} hashes)"