handheld-daemon-ui: 3.2.3 -> 3.3.0 (#361609)
[NixPkgs.git] / pkgs / development / tools / coder / update.sh
blob60e9a97af2217aaa389cc2c64f952465f387f6ad
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl jq common-updater-scripts
4 set -eu -o pipefail
6 cd "$(dirname "${BASH_SOURCE[0]}")"
8 # The released tagged as "latest" is always stable.
9 LATEST_STABLE_VERSION=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --fail -sSL https://api.github.com/repos/coder/coder/releases/latest | jq -r '.tag_name | sub("^v"; "")')
10 # The highest version that is not a pre-release is the latest mainline version.
11 LATEST_MAINLINE_VERSION=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --fail -sSL https://api.github.com/repos/coder/coder/releases | jq -r 'map(select(.prerelease == false)) | sort_by(.tag_name | sub("^v"; "") | split(".") | map(tonumber)) | .[-1].tag_name | sub("^v"; "")')
13 # Define the platforms
14 declare -A ARCHS=(["x86_64-linux"]="linux_amd64.tar.gz"
15 ["aarch64-linux"]="linux_arm64.tar.gz"
16 ["x86_64-darwin"]="darwin_amd64.zip"
17 ["aarch64-darwin"]="darwin_arm64.zip")
19 update_version_and_hashes() {
20 local version=$1
21 local channel=$2
23 # Update version number, using '#' as delimiter
24 sed -i "/${channel} = {/,/};/{
25 s#^\(\s*\)version = .*#\1version = \"$version\";#
26 }" ./default.nix
28 # Update hashes for each architecture
29 for ARCH in "${!ARCHS[@]}"; do
30 local URL="https://github.com/coder/coder/releases/download/v${version}/coder_${version}_${ARCHS[$ARCH]}"
31 echo "Fetching hash for $channel/$ARCH..."
33 # Fetch the new hash using nix-prefetch-url
34 local NEW_HASH=$(nix-prefetch-url --type sha256 $URL)
35 local SRI_HASH=$(nix hash to-sri --type sha256 $NEW_HASH)
37 # Update the Nix file with the new hash, using '#' as delimiter and preserving indentation
38 sed -i "/${channel} = {/,/};/{
39 s#^\(\s*\)${ARCH} = .*#\1${ARCH} = \"${SRI_HASH}\";#
40 }" ./default.nix
41 done
44 # Update stable channel
45 update_version_and_hashes $LATEST_STABLE_VERSION "stable"
47 # Update mainline channel
48 update_version_and_hashes $LATEST_MAINLINE_VERSION "mainline"