From 266e6279281efec8e685d7011e488a87922dc19c Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Wed, 20 Nov 2024 08:08:08 +0000 Subject: [PATCH] Fix installer downloads for specific releases (#1976) * 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. * ci: Set BINSTALL_VERSION in install script tests When running the install-script workflow in Github Actions, add matrix options for not setting the variable, setting it to the latest release with the `v` prefix, and setting it to the latest release without the `v` prefix. --- .github/workflows/install-script.yml | 41 ++++++++++++++++++++++++++++ install-from-binstall-release.ps1 | 15 ++++++++-- install-from-binstall-release.sh | 14 ++++++++-- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/.github/workflows/install-script.yml b/.github/workflows/install-script.yml index 409761623..62768b039 100644 --- a/.github/workflows/install-script.yml +++ b/.github/workflows/install-script.yml @@ -31,6 +31,7 @@ jobs: matrix: os: [macos-latest, ubuntu-latest] set_cargo_home: [t, f] + set_binstall_version: ['no', 'with-v', 'without-v'] runs-on: ${{ matrix.os }} @@ -44,6 +45,18 @@ jobs: mkdir -p "${CARGO_HOME}/bin" echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV" + - name: Set `BINSTALL_VERSION` + if: matrix.set_binstall_version != 'no' + env: + STRIP_V: ${{ matrix.set_cargo_home }} + GH_TOKEN: ${{ github.token }} + run: | + # fetch most recent release tag. + BINSTALL_VERSION="$(gh release list --json name --jq '[.[] | select(.name | startswith("v")) | .name] | first')" + if [[ $STRIP_V == 'without-v' ]]; then BINSTALL_VERSION="${BINSTALL_VERSION#v*}"; fi + echo "Setting BINSTALL_VERSION=$BINSTALL_VERSION" + echo "BINSTALL_VERSION=$BINSTALL_VERSION" >> "$GITHUB_ENV" + - name: Install `cargo-binstall` using scripts run: ./install-from-binstall-release.sh env: @@ -59,6 +72,7 @@ jobs: fail-fast: false matrix: set_cargo_home: [t, f] + set_binstall_version: ['no', 'with-v', 'without-v'] runs-on: windows-latest @@ -73,6 +87,19 @@ jobs: mkdir -p "${CARGO_HOME}/bin" echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV" + - name: Set `BINSTALL_VERSION` + if: matrix.set_binstall_version != 'no' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + STRIP_V: ${{ matrix.set_cargo_home }} + run: | + # fetch most recent release name. + BINSTALL_VERSION="$(gh release list --json name --jq '[.[] | select(.name | startswith("v")) | .name] | first')" + if [[ $STRIP_V == 'without-v' ]]; then BINSTALL_VERSION="${BINSTALL_VERSION#v*}"; fi + echo "Setting BINSTALL_VERSION=$BINSTALL_VERSION" + echo "BINSTALL_VERSION=$BINSTALL_VERSION" >> "$GITHUB_ENV" + - name: Install `cargo-binstall` using scripts run: ./install-from-binstall-release.ps1 env: @@ -86,6 +113,7 @@ jobs: fail-fast: false matrix: set_cargo_home: [t, f] + set_binstall_version: ['no', 'with-v', 'without-v'] runs-on: windows-latest @@ -100,6 +128,19 @@ jobs: mkdir -p "${CARGO_HOME}/bin" echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV" + - name: Set `BINSTALL_VERSION` + if: matrix.set_binstall_version != 'no' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + STRIP_V: ${{ matrix.set_cargo_home }} + run: | + # fetch most recent release name. + BINSTALL_VERSION="$(gh release list --json name --jq '[.[] | select(.name | startswith("v")) | .name] | first')" + if [[ $STRIP_V == 'without-v' ]]; then BINSTALL_VERSION="${BINSTALL_VERSION#v*}"; fi + echo "Setting BINSTALL_VERSION=$BINSTALL_VERSION" + echo "BINSTALL_VERSION=$BINSTALL_VERSION" >> "$GITHUB_ENV" + - name: Install `cargo-binstall` using scripts shell: bash run: ./install-from-binstall-release.sh diff --git a/install-from-binstall-release.ps1 b/install-from-binstall-release.ps1 index 4a31f878b..abbc8050e 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 97cf0cca5..2153a16c9 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