-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathsnapshot-bundled-cli-version.sh
More file actions
executable file
·65 lines (58 loc) · 2.11 KB
/
Copy pathsnapshot-bundled-cli-version.sh
File metadata and controls
executable file
·65 lines (58 loc) · 2.11 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
#!/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)"