Files
Jinjing 6ab23739ff fix(nix): harden update script with GitHub token auth and add .gitattributes (#54)
- fix(nix): harden update script with GitHub token auth and add .gitattributes

- fix(nix): harden update script with GitHub token auth and add .gitattributes
- fix issues
- fix issues
- fix issues
- fix issues
2026-03-06 21:45:44 -08:00

67 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo="stablyai/agent-slack"
latest_api="https://api.github.com/repos/${repo}/releases/latest"
if ! command -v jq >/dev/null 2>&1; then
echo "error: jq is required" >&2
exit 1
fi
if ! command -v nix >/dev/null 2>&1; then
echo "error: nix is required" >&2
exit 1
fi
curl_opts=(-fsSL)
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
curl_opts+=(-H "Authorization: token $GITHUB_TOKEN")
fi
tag="$(curl "${curl_opts[@]}" "$latest_api" | jq -r '.tag_name')"
if [[ -z "$tag" || "$tag" == "null" ]]; then
echo "error: unable to resolve latest release tag" >&2
exit 1
fi
version="${tag#v}"
checksums_url="https://github.com/${repo}/releases/download/${tag}/checksums-sha256.txt"
checksums="$(curl "${curl_opts[@]}" "$checksums_url")"
get_sri() {
local asset="$1"
local hex
hex="$(awk -v asset="$asset" '$2 == asset { print $1 }' <<<"$checksums")"
if [[ -z "$hex" ]]; then
echo "error: missing checksum for ${asset}" >&2
exit 1
fi
nix hash convert --hash-algo sha256 --to sri "$hex"
}
arm64_darwin="$(get_sri agent-slack-darwin-arm64)"
x64_darwin="$(get_sri agent-slack-darwin-x64)"
arm64_linux="$(get_sri agent-slack-linux-arm64)"
x64_linux="$(get_sri agent-slack-linux-x64)"
jq -n \
--arg version "$version" \
--arg aarch64_darwin "$arm64_darwin" \
--arg x86_64_darwin "$x64_darwin" \
--arg aarch64_linux "$arm64_linux" \
--arg x86_64_linux "$x64_linux" \
'{
version: $version,
hashes: {
"aarch64-darwin": $aarch64_darwin,
"x86_64-darwin": $x86_64_darwin,
"aarch64-linux": $aarch64_linux,
"x86_64-linux": $x86_64_linux
}
}' > nix/sources.json
echo "Updated nix/sources.json to ${version}"