Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions windows-release/stage-publish-nugetorg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ jobs:
workingDirectory: '$(Build.BinariesDirectory)\nuget'
condition: and(succeeded(), ne(variables['PublishARM64'], 'true'))

- powershell: |
$serviceIndex = Invoke-RestMethod -Uri 'https://api.nuget.org/v3/index.json' -ErrorAction Stop
$api = $serviceIndex.resources |
Where-Object { $_.'@type' -eq 'PackageBaseAddress/3.0.0' } |
Select-Object -First 1 -ExpandProperty '@id'
if (-not $api) {
throw 'Could not find the NuGet package base address'
}

foreach ($package in Get-ChildItem -Filter '*.nupkg' -File) {
if ($package.BaseName -notmatch '^([^.]+)\.(.+)$') {
throw "Could not determine the package ID and version from $($package.Name)"
}
$packageId = $Matches[1].ToLowerInvariant()
$packageVersion = $Matches[2].ToLowerInvariant()

try {
$versionsUri = "$api$packageId/index.json"
$versions = (Invoke-RestMethod -Uri $versionsUri -ErrorAction Stop).versions
} catch {
if ([int]$_.Exception.Response.StatusCode -eq 404) {
continue
}
throw
}

if ($versions -contains $packageVersion) {
Write-Host "Already published: $($package.Name)"
Remove-Item -LiteralPath $package.FullName
}
}
displayName: 'Skip already published NuGet packages'
workingDirectory: '$(Build.BinariesDirectory)\nuget'

- task: NuGetCommand@2
displayName: Push packages
condition: and(succeeded(), eq(variables['IsRealSigned'], 'true'))
Expand All @@ -39,3 +73,4 @@ jobs:
packagesToPush: '$(Build.BinariesDirectory)\nuget\*.nupkg'
nuGetFeedType: external
publishFeedCredentials: 'Python on Nuget'
requestTimeout: 600
Loading