Skip to content

Commit 8bf4a35

Browse files
java: switch to manual publishing via central API
1 parent ef990cd commit 8bf4a35

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

java/build-package.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ try {
7474
Write-Host "Copying 51degrees packages from local repo"
7575
Copy-Item -Recurse $mvnLocalRepo/com/51degrees $packagePath
7676

77-
Write-Host "Copying local maven staging directory"
78-
Copy-Item -Recurse target $packagePath
77+
Write-Host "Copying publishing bundle"
78+
Copy-Item target/central-publishing/central-bundle.zip $packagePath
7979
} finally {
8080
Write-Host "Leaving '$RepoName'"
8181
Pop-Location

java/install-package.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ try {
1515
Write-Host "Copying packages to the local repository"
1616
Copy-Item -Recurse "$packagePath/51degrees" "$mvnLocalRepo/com/51degrees"
1717

18-
Write-Host "Copying packages to the local staging repository"
19-
Copy-Item -Recurse "$packagePath/target" .
20-
2118
Write-Host "Local 51d maven repository contents:"
22-
Get-ChildItem $MavenLocal51DPath
19+
Get-ChildItem "$mvnLocalRepo/com/51degrees"
2320
} finally {
2421
Write-Host "Leaving '$RepoName'"
2522
Pop-Location

java/publish-package-maven.ps1

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
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
55
)
66
$ErrorActionPreference = "Stop"
77
$PSNativeCommandUseErrorActionPreference = $true
88

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"
1020

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
1823

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
2126

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
2733
}
34+
Write-Error "Reached maximum number of retries, giving up"

0 commit comments

Comments
 (0)