Skip to content

Commit

Permalink
Prevent script from exiting before processing all packages (#28370)
Browse files Browse the repository at this point in the history
* Prevent Publish-MavenPackages from exiting before processing all packages

* Skip hash comparison for jar files
  • Loading branch information
hallipr authored Apr 19, 2022
1 parent ac25422 commit d55e2cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
24 changes: 16 additions & 8 deletions eng/scripts/MavenPackaging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,26 @@ function Test-ReleasedPackage([string]$RepositoryUrl, [MavenPackageDetail]$Packa

if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 300) {
$remoteCount++
$remoteHash = $response.Content

Write-Information " Getting local hash"
$localPath = $artifact.File.FullName
$localHash = Get-FileHash -Path $localPath -Algorithm $algorithm | Select-Object -ExpandProperty 'Hash'

if ($remoteHash -eq $localHash) {
if ($artifact.File.Extension -ieq '.jar') {
# Because authenticode signing isn't determinsitic, we can't compare the hash of 2 separately signed jars
Write-Information " Remote hash of jar file esists."
$matchCount++
Write-Information " Remote $remoteHash == Local $localHash"
}
else {
Write-Information " Remote $remoteHash != Local $localHash"
$remoteHash = $response.Content

Write-Information " Getting local hash"
$localPath = $artifact.File.FullName
$localHash = Get-FileHash -Path $localPath -Algorithm $algorithm | Select-Object -ExpandProperty 'Hash'

if ($remoteHash -eq $localHash) {
$matchCount++
Write-Information " Remote $remoteHash == Local $localHash"
}
else {
Write-Information " Remote $remoteHash != Local $localHash"
}
}
}
else {
Expand Down
16 changes: 13 additions & 3 deletions eng/scripts/Publish-MavenPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,34 @@ foreach ($packageDetail in $packageDetails) {
}

$attempt = 0
$success = $false;

while ($attempt++ -lt 3) {
Write-Information "Releasing staging repostiory $stagedRepositoryId, attempt $attempt"
Write-Information "mvn org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:rc-release `"-DstagingRepositoryId=$stagedRepositoryId`" `"-DnexusUrl=https://oss.sonatype.org`" `"-DrepositoryId=target-repo`" `"-DserverId=target-repo`" `"-Drepo.username=$RepositoryUsername`" `"-Drepo.password=`"`"[redacted]`"`"`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`""
mvn org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:rc-release "-DstagingRepositoryId=$stagedRepositoryId" "-DnexusUrl=https://oss.sonatype.org" "-DrepositoryId=target-repo" "-DserverId=target-repo" "-Drepo.username=$RepositoryUsername" "-Drepo.password=""$RepositoryPassword""" "--settings=$PSScriptRoot\..\maven.publish.settings.xml"

if ($LASTEXITCODE -eq 0) {
Write-Information "Package $($packageDetail.FullyQualifiedName) deployed"
exit 0
$success = $true
break
}

Write-Information "Release attempt $attempt exited with code $LASTEXITCODE"
Write-Information "Checking Maven Central to see if release was successful"

if (Test-ReleasedPackage -RepositoryUrl $packageReposityUrl -PackageDetail $packageDetail) {
Write-Information "Package $($packageDetail.FullyQualifiedName) deployed despite non-zero exit code."
exit 0
$success = $true
break
}
}
exit 1

if (!$success) {
Write-Information '##vso[task.logissue type=error]Release to Maven Central failed. For troubleshooting, see https://aka.ms/azsdk/maven-central-tsg'
exit 1
}
}
}

exit 0

0 comments on commit d55e2cf

Please sign in to comment.