From 46ab6a5dd7c10f6a154a51d5685315dcd50a6f70 Mon Sep 17 00:00:00 2001 From: "azure-sdk-automation[bot]" <191533747+azure-sdk-automation[bot]@users.noreply.github.com> Date: Tue, 6 Oct 2026 01:34:17 -0700 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 17077 (#3858) --------- Co-authored-by: Anton Kolesnyk Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../scripts/Helpers/AzSdkTool-Helpers.ps1 | 81 ++++++++++++++----- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1 b/eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1 index 887e798ae..36f13435d 100644 --- a/eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1 +++ b/eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1 @@ -135,35 +135,73 @@ function Install-Standalone-Tool ( } $tag = "${Package}_${Version}" + $downloadUrlPrefix = "https://github.com/$Repository/releases/download" if (!$Version -or $Version -eq "*") { Write-Host "Attempting to find latest version for package '$Package'" $found = $false - # First attempt: use git ls-remote on repository tags to avoid GitHub REST API rate limits - try { - $remoteUrl = "https://github.com/$Repository.git" - $rawTags = git ls-remote --tags --refs --sort=-version:refname $remoteUrl "${Package}_*" - if ($rawTags) { - $matchingTags = @() - foreach ($line in $rawTags) { - if ($line -match "refs/tags/(${Package}_(?!.*dev)(.+))$") { - $matchingTags += [PSCustomObject]@{ - Tag = $matches[1] - Version = $matches[2] - } - } - } - if ($matchingTags.Count -gt 0) { - $latest = $matchingTags[0] - $tag = $latest.Tag - $Version = $latest.Version + if ($Package -eq "azsdk") { + $StorageAccount = "azuresdkartifacts" + $Container = "public-azsdk-cli" + try { + $Version = ( ` + [xml]( ` + [string]( ` + Invoke-RestMethod ` + -Uri "https://${StorageAccount}.blob.core.windows.net/${Container}?restype=container&comp=list&maxresults=100000" ` + -Method Get` + ) -replace "`u{FEFF}", "" ` + ) ` + ).EnumerationResults.Blobs ` + | Select-Object -ExpandProperty Blob ` + | Select-Object -ExpandProperty Name ` + | Select-String -Pattern "^${Package}_(?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*))/$([regex]::Escape($systemDetails.file_name))$" ` + | %{ [semver]$_.Matches.Captures.Groups["Version"].Value } ` + | Sort-Object -Descending ` + | Get-Unique ` + | %{ $_.ToString() } ` + | Select-Object -First 1 + + if ($Version) { + $tag = "${Package}_${Version}" + $downloadUrlPrefix = "https://${StorageAccount}.blob.core.windows.net/${Container}" $found = $true + Write-Host "Found the latest version of ${Package} ${Version} from ${StorageAccount}/${Container}" } } + catch { + Write-Host "Failed to get latest version from ${StorageAccount}/${Container}: $_" + } } - catch { - Write-Host "git ls-remote failed: $_. Falling back to GitHub REST API." + + if (!$found) { + # First attempt: use git ls-remote on repository tags to avoid GitHub REST API rate limits + try { + $remoteUrl = "https://github.com/$Repository.git" + $rawTags = git ls-remote --tags --refs --sort=-version:refname $remoteUrl "${Package}_*" + if ($rawTags) { + $matchingTags = @() + foreach ($line in $rawTags) { + if ($line -match "refs/tags/(${Package}_(?!.*dev)(.+))$") { + $matchingTags += [PSCustomObject]@{ + Tag = $matches[1] + Version = $matches[2] + } + } + } + if ($matchingTags.Count -gt 0) { + $latest = $matchingTags[0] + $tag = $latest.Tag + $Version = $latest.Version + $found = $true + Write-Host "Found the latest version of $Package $Version via git ls-remote" + } + } + } + catch { + Write-Host "git ls-remote failed: $_. Falling back to GitHub REST API." + } } # Fallback: GitHub REST API @@ -175,6 +213,7 @@ function Install-Standalone-Tool ( $tag = $release.tag_name $Version = $release.tag_name -replace "${Package}_", "" $found = $true + Write-Host "Found the latest version of $Package $Version via GitHub REST API" break } } @@ -186,7 +225,7 @@ function Install-Standalone-Tool ( } $downloadFolder = Resolve-Path $Directory - $downloadUrl = "https://github.com/$Repository/releases/download/$tag/$($systemDetails.file_name)" + $downloadUrl = "$downloadUrlPrefix/$tag/$($systemDetails.file_name)" $downloadFile = $downloadUrl.Split('/')[-1] $downloadLocation = Join-Path $downloadFolder $downloadFile $savedVersionTxt = Join-Path $downloadFolder "downloaded_version.txt"