From 30abb232cc620ae6030883be2028f6fcafb9c876 Mon Sep 17 00:00:00 2001 From: Vasileios Naskos Date: Wed, 4 Mar 2026 11:40:00 +0100 Subject: [PATCH] Use GitHub releases to fetch latest version --- .github/workflows/build.yml | 5 ----- user-scripts/install.ps1 | 16 ++++++++++------ user-scripts/install.sh | 14 +++++++------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef18f455..62eb7603 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -259,11 +259,6 @@ jobs: - name: Copy user scripts to dist run: cp user-scripts/install.sh user-scripts/install.ps1 dist/ - - name: Generate latest-version.txt - env: - PROJECT_VERSION: ${{ needs.prepare.outputs.PROJECT_VERSION }} - run: echo "${PROJECT_VERSION}" > dist/latest-version.txt - - name: Upload binaries to Artifactory env: ARTIFACTORY_URL: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_URL }} diff --git a/user-scripts/install.ps1 b/user-scripts/install.ps1 index f30c1a77..09c851c0 100644 --- a/user-scripts/install.ps1 +++ b/user-scripts/install.ps1 @@ -10,8 +10,14 @@ $BaseUrl = 'https://binaries.sonarsource.com/Distribution/sonarqube-cli' $Platform = 'windows-x86-64' function Resolve-LatestVersion { - $Version = (Invoke-WebRequest -Uri "$BaseUrl/latest-version.txt" -UseBasicParsing).Content.Trim() - if (-not $Version) { + $ReleasesUrl = 'https://github.com/SonarSource/sonarqube-cli/releases/latest' + $Request = [System.Net.WebRequest]::Create($ReleasesUrl) + $Request.AllowAutoRedirect = $true + $Response = $Request.GetResponse() + $FinalUrl = $Response.ResponseUri.AbsoluteUri + $Response.Close() + $Version = ($FinalUrl -split '/')[-1] -replace '^v', '' + if (-not $Version -or $Version -eq 'latest') { Write-Error 'Could not determine the latest version.' exit 1 } @@ -42,10 +48,8 @@ function Add-ToUserPath { # --- Main --- -#Write-Host 'Fetching latest version...' -#$SonarVersion = Resolve-LatestVersion - -$SonarVersion = "0.4.0.345" +Write-Host 'Fetching latest version...' +$SonarVersion = Resolve-LatestVersion Write-Host "Latest version: $SonarVersion" $Filename = "sonarqube-cli-$SonarVersion-$Platform.exe" diff --git a/user-scripts/install.sh b/user-scripts/install.sh index e2cea048..eaa570b0 100644 --- a/user-scripts/install.sh +++ b/user-scripts/install.sh @@ -30,18 +30,19 @@ detect_platform() { } resolve_latest_version() { + local releases_url="https://github.com/SonarSource/sonarqube-cli/releases/latest" local version if command -v curl &>/dev/null; then - version="$(curl -fsSL "$BASE_URL/latest-version.txt")" + version="$(curl -fsSL -o /dev/null -w '%{url_effective}' "$releases_url" | grep -oE '[^/]+$')" elif command -v wget &>/dev/null; then - version="$(wget -qO- "$BASE_URL/latest-version.txt")" + version="$(wget -qO /dev/null --server-response "$releases_url" 2>&1 | grep -i 'location:' | tail -1 | grep -oE '[^/]+$')" else echo "Error: neither curl nor wget is available. Please install one and retry." >&2 exit 1 fi - version="$(printf '%s' "$version" | tr -d '[:space:]')" - if [[ -z "$version" ]]; then + version="$(printf '%s' "$version" | tr -d '[:space:]' | sed 's/^v//')" + if [[ -z "$version" ]] || [[ "$version" == "latest" ]]; then echo "Error: could not determine the latest version." >&2 exit 1 fi @@ -68,9 +69,8 @@ main() { platform="$(detect_platform)" local version - #echo "Fetching latest version..." - #version="$(resolve_latest_version)" - version="0.4.0.345" + echo "Fetching latest version..." + version="$(resolve_latest_version)" echo "Latest version: $version" local filename="sonarqube-cli-${version}-${platform}.exe"