mirror of
https://github.com/microsoft/mcp.git
synced 2026-11-04 12:01:31 +00:00
Sync eng/common directory with azure-sdk-tools for PR 17056 (#3695)
Update helper scripts for tag version discovery Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: praveenkuttappan <55455725+praveenkuttappan@users.noreply.github.com>
This commit is contained in:
1 file changed
+39
-8
@@ -138,17 +138,48 @@ function Install-Standalone-Tool (
|
||||
|
||||
if (!$Version -or $Version -eq "*") {
|
||||
Write-Host "Attempting to find latest version for package '$Package'"
|
||||
$releasesUrl = "https://api.github.com/repos/$Repository/releases"
|
||||
$releases = Invoke-RestMethod -Uri $releasesUrl
|
||||
$found = $false
|
||||
foreach ($release in $releases) {
|
||||
if ($release.tag_name -like "$Package*") {
|
||||
$tag = $release.tag_name
|
||||
$Version = $release.tag_name -replace "${Package}_", ""
|
||||
$found = $true
|
||||
break
|
||||
|
||||
# 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
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "git ls-remote failed: $_. Falling back to GitHub REST API."
|
||||
}
|
||||
|
||||
# Fallback: GitHub REST API
|
||||
if (!$found) {
|
||||
$releasesUrl = "https://api.github.com/repos/$Repository/releases"
|
||||
$releases = Invoke-RestMethod -Uri $releasesUrl
|
||||
foreach ($release in $releases) {
|
||||
if ($release.tag_name -like "$Package*") {
|
||||
$tag = $release.tag_name
|
||||
$Version = $release.tag_name -replace "${Package}_", ""
|
||||
$found = $true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($found -eq $false) {
|
||||
throw "No release found for package '$Package'"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user