Skip to content

Commit 8c6b248

Browse files
authored
fix(ci): route NuGet version check through CFS (#3162)
* fix(ci): avoid blocked NuGet registration endpoint Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 03d194c7-5fba-4802-a182-3b3ef5c5c0ab * fix(ci): route NuGet version check through CFS Replace the direct public NuGet API request with dotnet package search using the authenticated Central Feed Service configuration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 03d194c7-5fba-4802-a182-3b3ef5c5c0ab * fix(ci): parse package search JSON as one document Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 03d194c7-5fba-4802-a182-3b3ef5c5c0ab --------- Copilot-Session: 03d194c7-5fba-4802-a182-3b3ef5c5c0ab
1 parent dee0ae2 commit 8c6b248

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

‎.azure-pipelines/ci-build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extends:
144144
inputs:
145145
targetType: filePath
146146
filePath: '$(Build.SourcesDirectory)\scripts\ValidateUpdatedNugetVersion.ps1'
147-
arguments: '-packageName "Microsoft.Graph" -projectPath "$(Build.SourcesDirectory)\src\Microsoft.Graph\Microsoft.Graph.csproj"'
147+
arguments: '-packageName "Microsoft.Graph" -projectPath "$(Build.SourcesDirectory)\src\Microsoft.Graph\Microsoft.Graph.csproj" -nugetConfigPath "$(Build.SourcesDirectory)\nuget.config"'
148148
pwsh: true
149149
enabled: true
150150
- task: EsrpCodeSigning@5

‎scripts/ValidateUpdatedNugetVersion.ps1‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
1717
.Parameter projectPath
1818
Specifies the path to the project file.
19+
20+
.Parameter nugetConfigPath
21+
Specifies the path to the NuGet configuration for the Central Feed Service.
1922
#>
2023

2124
Param(
2225
[parameter(Mandatory = $true)]
2326
[string]$packageName,
2427

2528
[parameter(Mandatory = $true)]
26-
[string]$projectPath
29+
[string]$projectPath,
30+
31+
[parameter(Mandatory = $true)]
32+
[string]$nugetConfigPath
2733
)
2834

2935
[xml]$xmlDoc = Get-Content $projectPath
@@ -38,25 +44,26 @@ if($xmlDoc.Project.PropertyGroup[0].VersionSuffix){
3844
# System.Version, get the version prefix.
3945
$currentProjectVersion = [System.Management.Automation.SemanticVersion]"$versionPrefixString"
4046

41-
# API is case-sensitive
42-
$packageName = $packageName.ToLower()
43-
$url = "https://api.nuget.org/v3/registration5-gz-semver2/$packageName/index.json"
44-
45-
# Call the NuGet API for the package and get the current published version.
4647
Try {
47-
$nugetIndex = Invoke-RestMethod -Uri $url -Method Get
48+
$searchResultJson = dotnet package search $packageName --configfile $nugetConfigPath --exact-match --prerelease --format json | Out-String
49+
if ($LASTEXITCODE -ne 0) {
50+
throw "dotnet package search exited with code $LASTEXITCODE"
51+
}
52+
53+
$searchResult = $searchResultJson | ConvertFrom-Json
54+
$matchingPackages = $searchResult.searchResult | ForEach-Object { $_.packages } | Where-Object { $_.id -ieq $packageName }
4855
}
4956
Catch {
50-
if ($_.ErrorDetails.Message && $_.ErrorDetails.Message.Contains("The specified blob does not exist.")) {
51-
Write-Host "No package exists. You will probably be publishing $packageName for the first time."
52-
Exit # exit gracefully
53-
}
54-
5557
Write-Host $_
5658
Exit 1
5759
}
5860

59-
$currentPublishedVersion = [System.Management.Automation.SemanticVersion]$nugetIndex.items[$nugetIndex.items.Count-1].upper
61+
if (-not $matchingPackages) {
62+
Write-Host "No package exists. You will probably be publishing $packageName for the first time."
63+
Exit # exit gracefully
64+
}
65+
66+
$currentPublishedVersion = ($matchingPackages | ForEach-Object { [System.Management.Automation.SemanticVersion]$_.version } | Sort-Object)[-1]
6067

6168
# Validate that the version number has been updated.
6269
if ($currentProjectVersion -le $currentPublishedVersion) {

0 commit comments

Comments
 (0)