nixpkgs/pkgs/development/tools/coder/update.sh
Kyle Carberry 73c3aa5bd0
coder: fix update script to use highest stable version (#306284)
* coder: use highest stable version not latest version

This would previously fetch 2.9.4 instead of 2.10.3 if 2.9.4 was
released afterwards. Coder frequently releases patches for older
versions, so we must sort by version.

This same pattern is done in their install script.

* Update pkgs/development/tools/coder/update.sh

Co-authored-by: superherointj <5861043+superherointj@users.noreply.github.com>

---------

Co-authored-by: superherointj <5861043+superherointj@users.noreply.github.com>
2024-04-25 11:58:11 -03:00

50 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts
set -eu -o pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
LATEST_STABLE_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"; "")')
# Fetch the latest mainline version
LATEST_MAINLINE_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/coder/coder/releases | jq -r '.[0].tag_name')
LATEST_MAINLINE_VERSION=$(echo ${LATEST_MAINLINE_TAG} | sed 's/^v//')
# Define the platforms
declare -A ARCHS=(["x86_64-linux"]="linux_amd64.tar.gz"
["aarch64-linux"]="linux_arm64.tar.gz"
["x86_64-darwin"]="darwin_amd64.zip"
["aarch64-darwin"]="darwin_arm64.zip")
update_version_and_hashes() {
local version=$1
local channel=$2
# Update version number, using '#' as delimiter
sed -i "/${channel} = {/,/};/{
s#^\(\s*\)version = .*#\1version = \"$version\";#
}" ./default.nix
# Update hashes for each architecture
for ARCH in "${!ARCHS[@]}"; do
local URL="https://github.com/coder/coder/releases/download/v${version}/coder_${version}_${ARCHS[$ARCH]}"
echo "Fetching hash for $channel/$ARCH..."
# Fetch the new hash using nix-prefetch-url
local NEW_HASH=$(nix-prefetch-url --type sha256 $URL)
local SRI_HASH=$(nix hash to-sri --type sha256 $NEW_HASH)
# Update the Nix file with the new hash, using '#' as delimiter and preserving indentation
sed -i "/${channel} = {/,/};/{
s#^\(\s*\)${ARCH} = .*#\1${ARCH} = \"${SRI_HASH}\";#
}" ./default.nix
done
}
# Update stable channel
update_version_and_hashes $LATEST_STABLE_VERSION "stable"
# Update mainline channel
update_version_and_hashes $LATEST_MAINLINE_VERSION "mainline"