Skip to content

Commit

Permalink
Refactor maven package version check to avoid retry delays (Azure#28185)
Browse files Browse the repository at this point in the history
* Fix groupid in url for maven package published check

* Refactor maven package version check to avoid retry delays
  • Loading branch information
hallipr authored Apr 12, 2022
1 parent 3c61310 commit a236b34
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,43 @@ function Get-java-PackageInfoFromRepo ($pkgPath, $serviceDirectory)
# Returns the maven (really sonatype) publish status of a package id and version.
function IsMavenPackageVersionPublished($pkgId, $pkgVersion, $groupId)
{
try
$uri = "https://oss.sonatype.org/content/repositories/releases/$($groupId.Replace('.', '/'))/$pkgId/$pkgVersion/$pkgId-$pkgVersion.pom"

$attempt = 1
while ($attempt -le 3)
{
$uri = "https://oss.sonatype.org/content/repositories/releases/$groupId/$pkgId/$pkgVersion/$pkgId-$pkgVersion.pom"
$pomContent = Invoke-RestMethod -MaximumRetryCount 3 -RetryIntervalSec 10 -Method "GET" -uri $uri

if ($pomContent -ne $null -or $pomContent.Length -eq 0)
try
{
return $true
if ($attempt -gt 1) {
Start-Sleep -Seconds ([Math]::Pow(2, $attempt))
}

Write-Host "Checking published package at $uri"
$response = Invoke-WebRequest -Method "GET" -uri $uri -SkipHttpErrorCheck

if ($response.BaseResponse.IsSuccessStatusCode)
{
return $true
}

$statusCode = $response.StatusCode

if ($statusCode -eq 404)
{
return $false
}

Write-Host "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed attempt $attempt with statuscode $statusCode"
}
else
catch
{
return $false
Write-Host "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed attempt $attempt with exception $($_.Exception.Message)"
}
}
catch
{
$statusCode = $_.Exception.Response.StatusCode.value__
$statusDescription = $_.Exception.Response.StatusDescription

# if this is 404ing, then this pkg has never been published before
if ($statusCode -eq 404) {
return $false
}

Write-Host "VersionCheck to maven for packageId $pkgId failed with statuscode $statusCode"
Write-Host $statusDescription
exit(1)
$attempt += 1
}

throw "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed after 3 attempts"
}

# Parse out package publishing information given a maven POM file
Expand Down

0 comments on commit a236b34

Please sign in to comment.