|
1 | 1 | param (
|
2 |
| - [Parameter(Mandatory)][string]$RepoName, |
3 |
| - [Parameter(Mandatory)][string]$Version, |
4 |
| - [Parameter(Mandatory)][string]$MavenSettings |
| 2 | + [Parameter(Mandatory)][string]$MavenSettings, |
| 3 | + $RepoName, # accepted for compatibility |
| 4 | + $Version # accepted for compatibility |
5 | 5 | )
|
6 | 6 | $ErrorActionPreference = "Stop"
|
7 | 7 | $PSNativeCommandUseErrorActionPreference = $true
|
8 | 8 |
|
9 |
| -$mvnSettings = "$PWD/java/settings.xml" |
| 9 | +$args = @{ |
| 10 | + ConnectionTimeoutSeconds = 30 |
| 11 | + OperationTimeoutSeconds = 30 |
| 12 | + Method = 'Post' |
| 13 | + Headers = @{Authorization = "Bearer $MavenSettings"} |
| 14 | +} |
| 15 | +$api = "https://central.sonatype.com/api/v1/publisher" |
| 16 | + |
| 17 | +Write-Host "Uploading the bundle..." |
| 18 | +$id = Invoke-WebRequest @args -Uri "$api/upload" -Form @{bundle = Get-Item package/central-bundle.zip; publishingType = 'AUTOMATIC'} |
| 19 | +Write-Host "Deployment id: $id" |
10 | 20 |
|
11 |
| -Write-Host "Entering '$RepoName'" |
12 |
| -Push-Location $RepoName |
13 |
| -try { |
14 |
| - # We need to set the version here again even though the packages are already built using the next version |
15 |
| - # as this script will run in a new job and the repo will be cloned again. |
16 |
| - Write-Host "Setting version to '$Version'" |
17 |
| - mvn --batch-mode --no-transfer-progress versions:set "-DnewVersion=$Version" |
| 21 | +for ($i = 1; $i -le 60; ++$i) { |
| 22 | + Start-Sleep -Seconds 10 |
18 | 23 |
|
19 |
| - $env:MVN_CENTRAL_USERNAME, $env:MVN_CENTRAL_PASSWORD = $MavenSettings -split ' ', 2 |
20 |
| - $env:MAVEN_OPTS='--add-opens=java.base/java.util=ALL-UNNAMED' |
| 24 | + Write-Host "Checking status ($i)..." |
| 25 | + $resp = Invoke-WebRequest @args -Uri "$api/status?id=$id" | ConvertFrom-Json |
21 | 26 |
|
22 |
| - Write-Host "Releasing to Maven central" |
23 |
| - mvn deploy --batch-mode --no-transfer-progress --settings $mvnSettings -DskipTests |
24 |
| -} finally { |
25 |
| - Write-Host "Leaving '$RepoName'" |
26 |
| - Pop-Location |
| 27 | + switch ($resp.deploymentState) { |
| 28 | + 'VALIDATED' {Write-Error "Deployment has passed validation and is waiting on a user to manually publish via the Central Portal UI"} |
| 29 | + 'FAILED' {Write-Error "Publishing failed:" $resp.errors} |
| 30 | + 'PUBLISHED' {Write-Host "Deployment successful"; exit 0} |
| 31 | + } |
| 32 | + # Retry on other statuses |
27 | 33 | }
|
| 34 | +Write-Error "Reached maximum number of retries, giving up" |
0 commit comments