-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathupdate-nix-sources.sh
More file actions
executable file
·66 lines (54 loc) · 1.67 KB
/
update-nix-sources.sh
File metadata and controls
executable file
·66 lines (54 loc) · 1.67 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
#!/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}"