-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsnapshot-bundled-cli-version.sh
More file actions
executable file
·67 lines (58 loc) · 2.1 KB
/
snapshot-bundled-cli-version.sh
File metadata and controls
executable file
·67 lines (58 loc) · 2.1 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
#!/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.
#
# Inputs:
# - ../nodejs/package-lock.json (sibling) - source of the pinned version.
# - https://github.com/github/copilot-cli/releases/v{version}/SHA256SUMS.txt -
# authoritative 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)"
LOCKFILE="${REPO_ROOT}/nodejs/package-lock.json"
OUTPUT="${RUST_DIR}/cli-version.txt"
if [[ ! -f "${LOCKFILE}" ]]; then
echo "error: ${LOCKFILE} not found" >&2
exit 1
fi
VERSION="$(node -e "console.log(require('${LOCKFILE}').packages['node_modules/@github/copilot'].version)")"
if [[ -z "${VERSION}" ]]; then
echo "error: could not read @github/copilot version from ${LOCKFILE}" >&2
exit 1
fi
CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/download/v${VERSION}/SHA256SUMS.txt"
echo "Fetching ${CHECKSUMS_URL}"
SHA256SUMS="$(curl -fsSL --retry 3 --retry-delay 2 "${CHECKSUMS_URL}")"
ASSETS=(
"copilot-darwin-arm64.tar.gz"
"copilot-darwin-x64.tar.gz"
"copilot-linux-arm64.tar.gz"
"copilot-linux-x64.tar.gz"
"copilot-win32-arm64.zip"
"copilot-win32-x64.zip"
)
declare -A HASHES
for asset in "${ASSETS[@]}"; do
hash="$(printf '%s\n' "${SHA256SUMS}" | awk -v a="${asset}" '$2 == a { print $1 }')"
if [[ -z "${hash}" ]]; then
echo "error: SHA256SUMS.txt missing entry for ${asset}" >&2
exit 1
fi
HASHES[$asset]="${hash}"
done
{
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
echo "${asset}=${HASHES[$asset]}"
done
} > "${OUTPUT}"
echo "Wrote ${OUTPUT} (version=${VERSION}, ${#ASSETS[@]} hashes)"