From 7b32f7cc252e515a95cb6d136e62cc649294170d Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Tue, 19 Nov 2024 12:24:11 +0000 Subject: [PATCH] Fix installer downloads for specific releases Github download urls for a specific release uses the pattern `../releases/download/[RELEASE]/..`, which differs from the latest release URL which uses `../releases/latest/download/..`. For convenience, if `BINSTALL_VERSION` is set but doesn't start with `v`, the v is prefixed. --- install-from-binstall-release.ps1 | 15 ++++++++++++--- install-from-binstall-release.sh | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/install-from-binstall-release.ps1 b/install-from-binstall-release.ps1 index 4a31f878..abbc8050 100644 --- a/install-from-binstall-release.ps1 +++ b/install-from-binstall-release.ps1 @@ -2,10 +2,19 @@ $ErrorActionPreference = "Stop" Set-PSDebug -Trace 1 $tmpdir = $Env:TEMP $BINSTALL_VERSION = $Env:BINSTALL_VERSION -if (-not $BINSTALL_VERSION) { - $BINSTALL_VERSION = 'latest' +if ($BINSTALL_VERSION -and $BINSTALL_VERSION -notlike 'v*') { + # prefix version with v + $BINSTALL_VERSION = "v$BINSTALL_VERSION" } -$base_url = "https://github.com/cargo-bins/cargo-binstall/releases/$BINSTALL_VERSION/download/cargo-binstall-" +# Fetch binaries from `[..]/releases/latest/download/[..]` if _no_ version is +# given, otherwise from `[..]/releases/download/VERSION/[..]`. Note the shifted +# location of '/download'. +$base_url = if (-not $BINSTALL_VERSION) { + "https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-" +} else { + "https://github.com/cargo-bins/cargo-binstall/releases/download/$BINSTALL_VERSION/cargo-binstall-" +} + $proc_arch = [Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", [EnvironmentVariableTarget]::Machine) if ($proc_arch -eq "AMD64") { $arch = "x86_64" diff --git a/install-from-binstall-release.sh b/install-from-binstall-release.sh index 97cf0cca..2153a16c 100755 --- a/install-from-binstall-release.sh +++ b/install-from-binstall-release.sh @@ -2,11 +2,21 @@ set -euxo pipefail -BINSTALL_VERSION="${BINSTALL_VERSION:-latest}" +if [[ -n "${BINSTALL_VERSION:-}" && "$BINSTALL_VERSION" != v* ]]; then + # prefix version with v + BINSTALL_VERSION="v$BINSTALL_VERSION" +fi cd "$(mktemp -d)" -base_url="https://github.com/cargo-bins/cargo-binstall/releases/${BINSTALL_VERSION}/download/cargo-binstall-" +# Fetch binaries from `[..]/releases/latest/download/[..]` if _no_ version is +# given, otherwise from `[..]/releases/download/VERSION/[..]`. Note the shifted +# location of '/download'. +if [[ -z "${BINSTALL_VERSION:-}" ]]; then + base_url="https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-" +else + base_url="https://github.com/cargo-bins/cargo-binstall/releases/download/${BINSTALL_VERSION}/cargo-binstall-" +fi os="$(uname -s)" if [ "$os" == "Darwin" ]; then