-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactor publish-mavenpackages #24070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,49 +121,92 @@ foreach ($packageDetail in $packageDetails) { | |
| $typesOption = "-Dtypes=$($commaDelimitedTypes.Substring(1))" | ||
| } | ||
|
|
||
| $shouldPublishPackage = $ShouldPublish | ||
| $packageReposityUrl = $RepositoryUrl | ||
|
|
||
| if ($packageReposityUrl -match "https://pkgs.dev.azure.com/azure-sdk/\b(internal|public)\b/*") { | ||
| # Azure DevOps feeds don't support staging | ||
| $shouldPublishPackage = $ShouldPublish -and !$StageOnly | ||
| $releaseType = 'AzureDevOps' | ||
| } | ||
| elseif ($packageReposityUrl -like "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { | ||
| if ($packageDetail.IsSnapshot) { | ||
| # Snapshots don't go to the standard maven central url | ||
| $packageReposityUrl = "https://oss.sonatype.org/content/repositories/snapshots/" | ||
| $releaseType = 'MavenCentralSnapshot' | ||
| } | ||
| elseif ($StageOnly) { | ||
| $releaseType = 'MavenCentralStaging' | ||
| } | ||
| else { | ||
| $releaseType = 'MavenCentral' | ||
| } | ||
| } | ||
| else { | ||
| throw "Repository URL must be either an Azure Artifacts feed, or a SonaType Nexus feed." | ||
| } | ||
|
|
||
| #Local GPG deployment is required when we're not going to publish a package, or when we're publishing to maven central | ||
| $requiresLocalGpg = !$shouldPublishPackage -or ($releaseType -eq 'MavenCentralStaging') -or ($releaseType -eq 'MavenCentral') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this all cases?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind I think I understand the logic now. For DevOps or Snapshot you will already be doing the steps that will generate the gpg files so you don't need to do it explicitly in those cases. |
||
|
|
||
| Write-Information "Release Type: $releaseType" | ||
| Write-Information "Should Publish Package: $shouldPublishPackage" | ||
| Write-Information "Requires local GPG deployment: $requiresLocalGpg" | ||
|
|
||
| Write-Information "Files Option is: $filesOption" | ||
| Write-Information "Classifiers Option is: $classifiersOption" | ||
| Write-Information "Types Option is: $typesOption" | ||
|
|
||
| $gpgexeOption = "-Dgpgexe=$GPGExecutablePath" | ||
| Write-Information "GPG Executable Option is: $gpgexeOption" | ||
|
|
||
| if ($RepositoryUrl -match "https://pkgs.dev.azure.com/azure-sdk/\b(internal|public)\b/*") { | ||
| if(!$ShouldPublish) | ||
| { | ||
| Write-Information "Skipping deployment because ShouldPublish == false." | ||
| continue | ||
| } | ||
| if ($requiresLocalGpg) { | ||
| $localRepositoryDirectory = Get-RandomRepositoryDirectory | ||
| $localRepositoryDirectoryUri = $([Uri]$localRepositoryDirectory.FullName).AbsoluteUri | ||
| Write-Information "Local Repository Directory URI is: $localRepositoryDirectoryUri" | ||
|
|
||
| if (Test-ReleasedPackage -RepositoryUrl $RepositoryUrl -PackageDetail $packageDetail -BearerToken $RepositoryPassword) { | ||
| Write-Information "Package $($packageDetail.FullyQualifiedName) already deployed. Skipping deployment." | ||
| continue | ||
| } | ||
| $urlOption = "-Durl=$localRepositoryDirectoryUri" | ||
| Write-Information "URL Option is: $urlOption" | ||
|
|
||
| Write-Information "GPG Signing and deploying package in one step to devops feed: $RepositoryUrl" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"-Durl=$RepositoryUrl`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"-Drepo.password=[redacted]`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "-Durl=$RepositoryUrl" "$gpgexeOption" "-DrepositoryId=target-repo" "-Drepo.password=$RepositoryPassword" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
| Write-Information "Signing and deploying package to $localRepositoryDirectoryUri" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"$urlOption`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "$urlOption" "$gpgexeOption" "-DrepositoryId=target-repo" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
| if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
| } | ||
| elseif ($RepositoryUrl -like "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { | ||
| if ($packageDetail.IsSnapshot) { | ||
| # If $StageOnly, don't release to /snapshots | ||
| # If snapshot, no need to stage first | ||
| $RepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/" | ||
| Write-Information "GPG Signing and deploying package in one step to Sonatype snapshots: $RepositoryUrl" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"-Durl=$RepositoryUrl`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"-Drepo.username=`"`"$RepositoryUsername`"`"`" `"-Drepo.password=[redacted]`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "-Durl=$RepositoryUrl" "$gpgexeOption" "-DrepositoryId=target-repo" "-Drepo.username=""$RepositoryUsername""" "-Drepo.password=""$RepositoryPassword""" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
| if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
|
||
| if(!$shouldPublishPackage) | ||
| { | ||
| Write-Information "Skipping deployment because Should Publish Package == false." | ||
| continue | ||
| } | ||
|
|
||
| if ($releaseType -eq 'AzureDevOps') { | ||
| Write-Information "GPG Signing and deploying package in one step to devops feed: $packageReposityUrl" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"-Durl=$packageReposityUrl`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"-Drepo.password=[redacted]`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "-Durl=$packageReposityUrl" "$gpgexeOption" "-DrepositoryId=target-repo" "-Drepo.password=$RepositoryPassword" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
|
|
||
| if ($LASTEXITCODE -eq 0) { | ||
| Write-Information "Package $($packageDetail.FullyQualifiedName) deployed" | ||
| continue | ||
| } | ||
|
|
||
| $localRepositoryDirectory = Get-RandomRepositoryDirectory | ||
| $localRepositoryDirectoryUri = $([Uri]$localRepositoryDirectory.FullName).AbsoluteUri | ||
| Write-Information "Local Repository Directory URI is: $localRepositoryDirectoryUri" | ||
|
|
||
| $urlOption = "-Durl=$localRepositoryDirectoryUri" | ||
| Write-Information "URL Option is: $urlOption" | ||
| Write-Information "Release attempt $attemt exited with code $LASTEXITCODE" | ||
| Write-Information "Checking Azure DevOps to see if release was successful" | ||
| if (Test-ReleasedPackage -RepositoryUrl $packageReposityUrl -PackageDetail $packageDetail) { | ||
| Write-Information "Package $($packageDetail.FullyQualifiedName) deployed despite non-zero exit code." | ||
| continue | ||
| } | ||
|
|
||
| exit $LASTEXITCODE | ||
| } | ||
| elseif ($releaseType -eq 'MavenCentralSnapshot') { | ||
| Write-Information "GPG Signing and deploying package in one step to Sonatype snapshots: $packageReposityUrl" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"-Durl=$packageReposityUrl`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"-Drepo.username=`"`"$RepositoryUsername`"`"`" `"-Drepo.password=[redacted]`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "-Durl=$packageReposityUrl" "$gpgexeOption" "-DrepositoryId=target-repo" "-Drepo.username=""$RepositoryUsername""" "-Drepo.password=""$RepositoryPassword""" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
| if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
| } | ||
| else { | ||
| # Maven Central Staging + optional Release | ||
| $repositoryDirectoryOption = "-DrepositoryDirectory=$localRepositoryDirectory" | ||
| Write-Information "Repository Directory Option is: $repositoryDirectoryOption" | ||
|
|
||
|
|
@@ -173,26 +216,6 @@ foreach ($packageDetail in $packageDetails) { | |
| $stagingDescriptionOption = "-DstagingDescription=$($packageDetail.FullyQualifiedName)" | ||
| Write-Information "Staging Description Option is: $stagingDescriptionOption" | ||
|
|
||
| Write-Information "Signing and deploying package to $localRepositoryDirectoryUri" | ||
| Write-Information "mvn gpg:sign-and-deploy-file `"--batch-mode`" `"$pomOption`" `"$fileOption`" `"$javadocOption`" `"$sourcesOption`" `"$filesOption`" $classifiersOption `"$typesOption`" `"$urlOption`" `"$gpgexeOption`" `"-DrepositoryId=target-repo`" `"--settings=$PSScriptRoot\..\maven.publish.settings.xml`"" | ||
| mvn gpg:sign-and-deploy-file "--batch-mode" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" $classifiersOption "$typesOption" "$urlOption" "$gpgexeOption" "-DrepositoryId=target-repo" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
| if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
|
||
| if(!$ShouldPublish) | ||
| { | ||
| Write-Information "Skipping deployment because ShouldPublish == false." | ||
| continue | ||
| } | ||
|
|
||
| if (!$StageOnly) { | ||
| Write-Information "Checking to see if package $($packageDetail.FullyQualifiedName) is already deployed." | ||
|
|
||
| if (Test-ReleasedPackage -RepositoryUrl $RepositoryUrl -PackageDetail $packageDetail) { | ||
| Write-Information "Package $($packageDetail.FullyQualifiedName) already deployed. Skipping deployment." | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| Write-Information "Staging package to Maven Central" | ||
| Write-Information "mvn org.sonatype.plugins:nexus-staging-maven-plugin:deploy-staged-repository `"--batch-mode`" `"-DnexusUrl=https://oss.sonatype.org`" `"$repositoryDirectoryOption`" `"$stagingProfileIdOption`" `"$stagingDescriptionOption`" `"-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:deploy-staged-repository "--batch-mode" "-DnexusUrl=https://oss.sonatype.org" "$repositoryDirectoryOption" "$stagingProfileIdOption" "$stagingDescriptionOption" "-DrepositoryId=target-repo" "-DserverId=target-repo" "-Drepo.username=$RepositoryUsername" "-Drepo.password=""$RepositoryPassword""" "--settings=$PSScriptRoot\..\maven.publish.settings.xml" | ||
|
|
@@ -207,36 +230,33 @@ foreach ($packageDetail in $packageDetails) { | |
| $stagedRepositoryUrl = $stagedRepositoryProperties["stagingRepository.url"] | ||
| Write-Information "Staging Repository URL is: $stagedRepositoryUrl" | ||
|
|
||
| if ($StageOnly) { | ||
| Write-Information "Skipping release of staging repository because stage only is set to false." | ||
| if ($releaseType -eq 'MavenCentralStaging') { | ||
| Write-Information "Skipping release of staging repository because Stage Only == true." | ||
| continue | ||
| } | ||
| else { | ||
| $attempt = 0 | ||
| while ($attempt++ -lt 3) { | ||
| Write-Information "Releasing staging repostiory $stagedRepositoryId, attempt $attempt" | ||
| Write-Information "mvn org.sonatype.plugins:nexus-staging-maven-plugin: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: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" | ||
| break | ||
| } | ||
|
|
||
| Write-Information "Release attempt $attemt exited with code $LASTEXITCODE" | ||
| Write-Information "Checking Maven Central to see if release was successful" | ||
|
|
||
| if (Test-ReleasedPackage -RepositoryUrl $RepositoryUrl -PackageDetail $packageDetail) { | ||
| Write-Information "Package $($packageDetail.FullyQualifiedName) deployed despite non-zero exit code." | ||
| break | ||
| } | ||
|
|
||
| if ($attempt -ge 3) { | ||
| exit $LASTEXITCODE | ||
| } | ||
|
|
||
| $attempt = 0 | ||
| while ($attempt++ -lt 3) { | ||
| Write-Information "Releasing staging repostiory $stagedRepositoryId, attempt $attempt" | ||
| Write-Information "mvn org.sonatype.plugins:nexus-staging-maven-plugin: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: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" | ||
| break | ||
| } | ||
|
|
||
| Write-Information "Release attempt $attemt 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." | ||
| break | ||
| } | ||
|
|
||
| if ($attempt -ge 3) { | ||
| exit $LASTEXITCODE | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| throw "Repository URL must be either an Azure Artifacts feed, or a SonaType Nexus feed." | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should make releaseType an input parameter to the script?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's reliably implicit from the uri. As is, there's no chance of conflict, just the possibility of someone calling us with an incorrect uri. If we add the parameter, then we'd have to check for an unsupported uri and for uris that don't match the releaseType parameter.