Skip to content

Commit 305c7d8

Browse files
authored
Resolve last release-related Network Isolation issues (#46456)
* ensure that we attempt to download the version from our feed (with upstream) enabled instead of going directly to pypi * ensure lastexitcode doesn't leak out * address usepythonversion ordering in the release stages. python 3.9 cannot be activate unless PIP_INDEX_URL is set to internal feed
1 parent e8d8907 commit 305c7d8

2 files changed

Lines changed: 52 additions & 18 deletions

File tree

eng/pipelines/templates/stages/archetype-python-release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,17 @@ stages:
124124
runOnce:
125125
deploy:
126126
steps:
127-
128-
- task: UsePythonVersion@0
129-
inputs:
130-
versionSpec: '3.9'
131-
132127
- template: /eng/pipelines/templates/steps/auth-dev-feed.yml
133128
parameters:
134129
DevFeedName: ${{ parameters.DevFeedName }}
135130
EnableTwineAuth: false
136131
EnablePipAuth: true
137132
EnableUvAuth: false
138133

134+
- task: UsePythonVersion@0
135+
inputs:
136+
versionSpec: '3.9'
137+
139138
- script: |
140139
python -m pip install -r $(Pipeline.Workspace)/release_artifact/release_requirements.txt
141140
displayName: Install Release Dependencies
@@ -199,6 +198,13 @@ stages:
199198
artifact: ${{parameters.ArtifactName}}
200199
timeoutInMinutes: 5
201200

201+
- template: /eng/pipelines/templates/steps/auth-dev-feed.yml
202+
parameters:
203+
DevFeedName: ${{ parameters.DevFeedName }}
204+
EnableTwineAuth: false
205+
EnablePipAuth: true
206+
EnableUvAuth: false
207+
202208
- task: UsePythonVersion@0
203209
inputs:
204210
versionSpec: '3.9'

eng/scripts/Language-Settings.ps1

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,29 +220,57 @@ function Get-AllPackageInfoFromRepo ($serviceDirectory)
220220
}
221221

222222
# Returns the pypi publish status of a package id and version.
223+
# Uses pip download against the configured package index (PIP_INDEX_URL) rather than
224+
# calling pypi.org directly, so this works in network-isolated (CFS) environments.
225+
# The Azure Artifacts feed has upstream to PyPI, so packages on PyPI are still found.
223226
function IsPythonPackageVersionPublished($pkgId, $pkgVersion)
224227
{
228+
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "pkg-verify-$([System.Guid]::NewGuid())"
229+
New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
230+
225231
try
226232
{
227-
$existingVersion = (Invoke-RestMethod -MaximumRetryCount 3 -RetryIntervalSec 10 -Method "Get" -uri "https://pypi.org/pypi/$pkgId/$pkgVersion/json").info.version
228-
# if existingVersion exists, then it's already been published
229-
return $True
230-
}
231-
catch
232-
{
233-
$statusCode = $_.Exception.Response.StatusCode.value__
234-
$statusDescription = $_.Exception.Response.StatusDescription
233+
Write-Host "Checking whether $pkgId==$pkgVersion is already published (using pip download)"
234+
235+
$pipArgs = @("download", "--no-deps", "--no-cache-dir", "--dest", $tmpDir, "$pkgId==$pkgVersion")
236+
237+
if ($env:PIP_INDEX_URL) {
238+
Write-Host "Using index from PIP_INDEX_URL"
239+
}
240+
else {
241+
Write-Host "PIP_INDEX_URL is not set; pip will fall back to public PyPI."
242+
}
243+
244+
$pipOutput = pip $pipArgs 2>&1
245+
$pipExitCode = $LASTEXITCODE
246+
# Reset $LASTEXITCODE so a non-zero pip exit code doesn't leak out and cause
247+
# the PowerShell ADO task to report failure after the script finishes.
248+
$global:LASTEXITCODE = 0
235249

236-
# if this is 404ing, then this pkg has never been published before
237-
if ($statusCode -eq 404)
250+
if ($pipExitCode -eq 0)
238251
{
252+
Write-Host "Package $pkgId==$pkgVersion was found on the package index."
253+
return $True
254+
}
255+
256+
$outputStr = $pipOutput -join "`n"
257+
258+
# pip reports "No matching distribution found" when the version doesn't exist.
259+
if ($outputStr -match "No matching distribution found" -or $outputStr -match "Could not find a version that satisfies")
260+
{
261+
Write-Host "Package $pkgId==$pkgVersion was not found on the package index (not yet published)."
239262
return $False
240263
}
241-
Write-Host "PyPI Invocation failed:"
242-
Write-Host "StatusCode:" $statusCode
243-
Write-Host "StatusDescription:" $statusDescription
264+
265+
# Any other failure is unexpected — fail hard to avoid accidentally re-publishing.
266+
Write-Host "Package version check failed unexpectedly:"
267+
Write-Host $outputStr
244268
exit(1)
245269
}
270+
finally
271+
{
272+
Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
273+
}
246274
}
247275

248276
# Parse out package publishing information given a python sdist of tar.gz format.

0 commit comments

Comments
 (0)