-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ESRP Release to Maven Central
- Loading branch information
Showing
4 changed files
with
239 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
parameters: | ||
ArtifactDirectory: not-specified | ||
OutputDirectory: not-specified | ||
RepositoryUrl: not-specified | ||
GroupID: | ||
ArtifactID: | ||
|
@@ -80,4 +81,34 @@ steps: | |
-GPGExecutablePath ${{ parameters.GPGExecutablePath }} | ||
-StageOnly:$${{parameters.StageOnly}} | ||
-ShouldPublish:$${{parameters.ShouldPublish}} | ||
-InformationAction Continue | ||
-InformationAction Continue | ||
- ${{if eq(parameters.Target, 'EsrpRelease')}}: | ||
- task: PowerShell@2 | ||
name: gpgSign | ||
displayName: 'Gpg sign and hash packages' | ||
inputs: | ||
pwsh: true | ||
workingDirectory: $(Agent.BuildDirectory) | ||
filePath: ${{ parameters.JavaRepoRoot }}/eng/scripts/SignAndHash-MavenPackages.ps1 | ||
arguments: > | ||
-Path ${{ parameters.ArtifactDirectory }} | ||
-DestinationPath ${{ parameters.OutputDirectory }} | ||
-GroupIDFilter "${{ parameters.GroupID }}" | ||
-ArtifactIDFilter "${{ parameters.ArtifactID }}" | ||
-GPGExecutablePath ${{ parameters.GPGExecutablePath }} | ||
-InformationAction Continue | ||
- ${{if and(eq(parameters.ShouldPublish, 'true'), ne(parameters.StageOnly, 'true'))}}: | ||
- task: EsrpRelease@1 | ||
displayName: 'Publish to ESRP' | ||
inputs: | ||
ConnectedServiceName: 'ESRP Release Service' | ||
Intent: 'PackageDistribution' | ||
ContentType: 'Maven' | ||
PackageLocation: $(gpgSign.packageLocation) | ||
Owners: '[email protected]' | ||
Approvers: '[email protected]' | ||
ServiceEndpointUrl: 'https://api.esrp.microsoft.com' | ||
MainPublisher: 'ESRPRELPACMANTEST' | ||
DomainTenantId: '72f988bf-86f1-41af-91ab-2d7cd011db47' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
#Requires -Version 7 | ||
|
||
param( | ||
[Parameter(Mandatory=$true)][string]$Path, | ||
[Parameter(Mandatory=$true)][string]$DestinationPath, | ||
[Parameter(Mandatory=$true)][string]$GPGExecutablePath, | ||
[Parameter(Mandatory=$false)][AllowEmptyString()][string]$GroupIDFilter, | ||
[Parameter(Mandatory=$false)][AllowEmptyString()][string]$ArtifactIDFilter | ||
) | ||
|
||
Set-StrictMode -Version 2.0 | ||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
. $PSScriptRoot\MavenPackaging.ps1 | ||
|
||
# The Resolve-Path will normalize the path separators and throw if they don't exist. | ||
# This is necessary because, the yml passes in ${{parameters.BuildToolsPath}}/ which | ||
# on Windows means <drive>:\<BuildToolsPath>/<whatever>/<else>. Maven doesn't always | ||
# behave well with different separators in the path. | ||
$Path = Resolve-Path $Path | ||
$GPGExecutablePath = Resolve-Path $GPGExecutablePath | ||
|
||
function Get-RandomRepositoryDirectory() { | ||
Write-Host "Getting random repository directory." | ||
$randomSubDirectoryName = [System.IO.Path]::GetRandomFileName() | ||
$randomRepositoryDirectory = New-Item -Type Directory -Path $env:TEMP -Name $randomSubDirectoryName | ||
Write-Host "Random repository directory is: $randomRepositoryDirectory" | ||
return $randomRepositoryDirectory | ||
} | ||
|
||
function ConvertTo-DeploymentDetails($PackageDetail) { | ||
$pomArtifact = $packageDetail.AssociatedArtifacts | Where-Object { ($null -eq $_.Classifier) -and ($_.Type -eq "pom") } | ||
|
||
$fileArtifact = $packageDetail.AssociatedArtifacts.Length -eq 1 ` | ||
? $packageDetail.AssociatedArtifacts[0] ` | ||
: ($packageDetail.AssociatedArtifacts | Where-Object { ($null -eq $_.Classifier) -and (($_.Type -eq "jar") -or ($_.Type -eq "aar")) }) | ||
|
||
$javadocArtifact = $packageDetail.AssociatedArtifacts | Where-Object { ($_.Classifier -eq "javadoc") -and ($_.Type -eq "jar")} | ||
|
||
$sourcesArtifact = $packageDetail.AssociatedArtifacts | Where-Object { ($_.Classifier -eq "sources") -and ($_.Type -eq "jar") } | ||
|
||
[AssociatedArtifact[]]$additionalArtifacts = $packageDetail.AssociatedArtifacts | Where-Object { | ||
($_ -ne $pomArtifact) -and | ||
($_ -ne $fileArtifact) -and | ||
($_ -ne $javadocArtifact) -and | ||
($_ -ne $sourcesArtifact) | ||
} | ||
|
||
return [ordered]@{ | ||
FullyQualifiedName= $packageDetail.FullyQualifiedName; | ||
GroupId= $packageDetail.GroupId; | ||
ArtifactId= $packageDetail.ArtifactId; | ||
Version= $packageDetail.Version; | ||
PomArtifact= $pomArtifact; | ||
FileArtifact= $fileArtifact; | ||
JavadocArtifact= $javadocArtifact; | ||
SourcesArtifact= $sourcesArtifact; | ||
AdditionalArtifacts= $additionalArtifacts; | ||
} | ||
} | ||
|
||
|
||
Write-Host "PS Script Root is: $PSScriptRoot" | ||
Write-Host "Path is: $Path" | ||
Write-Host "DestinationPath is: $DestinationPath" | ||
Write-Host "GPG Executable Path is: $GPGExecutablePath" | ||
Write-Host "Group ID Filter is: $GroupIDFilter" | ||
Write-Host "Artifact ID Filter is: $ArtifactIDFilter" | ||
|
||
Write-Host "Getting filtered package details." | ||
|
||
[array]$packageDetails = Get-FilteredMavenPackageDetails -ArtifactDirectory $Path -GroupIDFilter $GroupIDFilter -ArtifactIDFilter $ArtifactIDFilter | ||
| ForEach-Object { ConvertTo-DeploymentDetails $_ } | ||
|
||
Write-Host "Found $($packageDetails.Length) packages to publish:" | ||
$packageDetails | ForEach-Object { Write-Host $_.FullyQualifiedName } | ||
|
||
if ($packageDetails.Length -eq 0) { | ||
throw "Aborting, no packages to publish." | ||
} | ||
|
||
Write-Host "Creating destination directory $DestinationPath" | ||
if (Test-Path $DestinationPath) { | ||
Remove-Item $DestinationPath -Force -Recurse | Out-Null | ||
} | ||
New-Item -Path $DestinationPath -Type Directory | Out-Null | ||
|
||
$DestinationPath = Resolve-Path -Path $DestinationPath | ||
$destinationPathUri = $([Uri]$DestinationPath).AbsoluteUri | ||
|
||
foreach ($packageDetail in $packageDetails) { | ||
Write-Host "GPG signing and publishing package: $($packageDetail.FullyQualifiedName)" | ||
|
||
$pomOption = "-DpomFile=$($packageDetail.PomArtifact.File.FullName)" | ||
Write-Host "POM Option is: $pomOption" | ||
|
||
$fileOption = "-Dfile=$($packageDetail.FileArtifact.File.FullName)" | ||
Write-Host "File Option is: $fileOption" | ||
|
||
$javadocOption = "" | ||
if (-not $packageDetail.JavadocArtifact) { | ||
Write-Host "No JavaDoc artifact, omitting JavaDoc Option" | ||
} else { | ||
$javadocOption = "-Djavadoc=$($packageDetail.JavadocArtifact.File.FullName)" | ||
Write-Host "JavaDoc Option is: $javadocOption" | ||
} | ||
|
||
$sourcesOption = "" | ||
if (-not $packageDetail.SourcesArtifact) { | ||
Write-Host "No Sources artifact, omitting Sources Option" | ||
} else { | ||
$sourcesOption = "-Dsources=$($packageDetail.SourcesArtifact.File.FullName)" | ||
Write-Host "Sources Option is: $sourcesOption" | ||
} | ||
|
||
foreach ($additionalArtifact in $packageDetail.AdditionalArtifacts) { | ||
Write-Host "Additional associated artifact is: $($additionalArtifact.File.FullName)" | ||
} | ||
|
||
$commaDelimitedFileNames = "" | ||
$commaDelimitedClassifiers = "" | ||
$commaDelimitedTypes = "" | ||
|
||
if ($null -ne $packageDetail.AdditionalArtifacts) { | ||
foreach($additionalArtifact in $packageDetail.AdditionalArtifacts) { | ||
$commaDelimitedFileNames += ",$($additionalArtifact.File.FullName)" | ||
$commaDelimitedClassifiers += ",$($additionalArtifact.Classifier)" | ||
$commaDelimitedTypes += ",$($additionalArtifact.Type)" | ||
} | ||
} | ||
|
||
$filesOption = "-Dfiles=$($commaDelimitedFileNames.Substring(1))" | ||
$classifiersOption = "-Dclassifiers=$($commaDelimitedClassifiers.Substring(1))" | ||
$typesOption = "-Dtypes=$($commaDelimitedTypes.Substring(1))" | ||
|
||
Write-Host "Files Option is: $filesOption" | ||
Write-Host "Classifiers Option is: $classifiersOption" | ||
Write-Host "Types Option is: $typesOption" | ||
|
||
$gpgexeOption = "-Dgpgexe=$GPGExecutablePath" | ||
Write-Host "GPG Executable Option is: $gpgexeOption" | ||
|
||
$urlOption = "-Durl=$destinationPathUri" | ||
Write-Host "URL Option is: $urlOption" | ||
|
||
$settingsOption = "--settings=$(Join-Path $PSScriptRoot '..' 'maven.publish.settings.xml' -Resolve)" | ||
Write-Host "Settings Option is: $settingsOption" | ||
|
||
Write-Host "" | ||
Write-Host "Signing package" | ||
|
||
Write-Host @" | ||
mvn gpg:sign-and-deploy-file "--batch-mode" "-Daether.checksums.algorithms=SHA-256,MD5,SHA-1" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" "$classifiersOption" "$typesOption" "$urlOption" "$gpgexeOption" "-DrepositoryId=target-repo" "$settingsOption" | ||
"@ | ||
|
||
mvn gpg:sign-and-deploy-file "--batch-mode" "-Daether.checksums.algorithms=SHA-256,MD5,SHA-1" "$pomOption" "$fileOption" "$javadocOption" "$sourcesOption" "$filesOption" "$classifiersOption" "$typesOption" "$urlOption" "$gpgexeOption" "-DrepositoryId=target-repo" "$settingsOption" | ||
|
||
if ($LASTEXITCODE) { exit $LASTEXITCODE } | ||
|
||
$groupId = $packageDetail.GroupId | ||
$artifactId = $packageDetail.ArtifactId | ||
$version = $packageDetail.Version | ||
|
||
$relativePath = "$($groupId.Replace('.', '/'))/$artifactId/$version" | ||
$signedArtifactPath = Join-Path $DestinationPath $relativePath | ||
|
||
if (-not (Test-Path $signedArtifactPath)) { | ||
Write-Error "Unable to located expected gpg output folder $signedArtifactPath" | ||
exit 1 | ||
} | ||
|
||
Write-Host "##vso[task.setvariable variable=packageLocation;isoutput=true]$signedArtifactPath" | ||
Write-Host "" | ||
} | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters