Skip to content

Commit ab730f1

Browse files
authored
new process for publishing snapshots and releases to Sonatype (#2535)
* add bash script to upload from the staging area to the portal * update the names/URLs/credentials of Sonatype publishing tasks * main.yml: invoke the uploadToCentral.sh script
1 parent d73bac2 commit ab730f1

File tree

3 files changed

+111
-32
lines changed

3 files changed

+111
-32
lines changed

.github/workflows/main.yml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# >> Configure MINIO NATIVES SNAPSHOT
1717
# OBJECTS_KEY=XXXXXX
1818
# >> Configure SONATYPE RELEASE
19-
# OSSRH_PASSWORD=XXXXXX
20-
# OSSRH_USERNAME=XXXXXX
19+
# CENTRAL_PASSWORD=XXXXXX
20+
# CENTRAL_USERNAME=XXXXXX
2121
# >> Configure SIGNING
2222
# SIGNING_KEY=XXXXXX
2323
# SIGNING_PASSWORD=XXXXXX
@@ -359,16 +359,16 @@ jobs:
359359
name: android-natives
360360
path: build/native
361361

362-
- name: Rebuild the maven artifacts and deploy them to the Sonatype repository
362+
- name: Rebuild the maven artifacts and upload them to Sonatype's maven-snapshots repo
363363
run: |
364-
if [ "${{ secrets.OSSRH_PASSWORD }}" = "" ];
364+
if [ "${{ secrets.CENTRAL_PASSWORD }}" = "" ];
365365
then
366-
echo "Configure the following secrets to enable deployment to Sonatype:"
367-
echo "OSSRH_PASSWORD, OSSRH_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
366+
echo "Configure the following secrets to enable uploading to Sonatype:"
367+
echo "CENTRAL_PASSWORD, CENTRAL_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
368368
else
369369
./gradlew publishMavenPublicationToSNAPSHOTRepository \
370-
-PossrhPassword=${{ secrets.OSSRH_PASSWORD }} \
371-
-PossrhUsername=${{ secrets.OSSRH_USERNAME }} \
370+
-PcentralPassword=${{ secrets.CENTRAL_PASSWORD }} \
371+
-PcentralUsername=${{ secrets.CENTRAL_USERNAME }} \
372372
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
373373
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
374374
-PuseCommitHashAsVersionName=true \
@@ -390,7 +390,7 @@ jobs:
390390
with:
391391
fetch-depth: 1
392392

393-
# Setup jdk 21 used for building Sonatype OSSRH artifacts
393+
# Setup jdk 21 used for building Sonatype artifacts
394394
- name: Setup the java environment
395395
uses: actions/setup-java@v4
396396
with:
@@ -416,20 +416,23 @@ jobs:
416416
name: android-natives
417417
path: build/native
418418

419-
- name: Rebuild the maven artifacts and deploy them to Sonatype OSSRH
419+
- name: Rebuild the maven artifacts and upload them to Sonatype's Central Publisher Portal
420420
run: |
421-
if [ "${{ secrets.OSSRH_PASSWORD }}" = "" ];
421+
if [ "${{ secrets.CENTRAL_PASSWORD }}" = "" ];
422422
then
423-
echo "Configure the following secrets to enable deployment to Sonatype:"
424-
echo "OSSRH_PASSWORD, OSSRH_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
423+
echo "Configure the following secrets to enable uploading to Sonatype:"
424+
echo "CENTRAL_PASSWORD, CENTRAL_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
425425
else
426-
./gradlew publishMavenPublicationToOSSRHRepository \
427-
-PossrhPassword=${{ secrets.OSSRH_PASSWORD }} \
428-
-PossrhUsername=${{ secrets.OSSRH_USERNAME }} \
429-
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
430-
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
431-
-PuseCommitHashAsVersionName=true \
432-
--console=plain --stacktrace
426+
./gradlew publishMavenPublicationToCentralRepository \
427+
-PcentralPassword=${{ secrets.CENTRAL_PASSWORD }} \
428+
-PcentralUsername=${{ secrets.CENTRAL_USERNAME }} \
429+
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
430+
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
431+
-PuseCommitHashAsVersionName=true \
432+
--console=plain --stacktrace
433+
./uploadToCentral.sh \
434+
-p '${{ secrets.CENTRAL_PASSWORD }}' \
435+
-u '${{ secrets.CENTRAL_USERNAME }}'
433436
fi
434437
435438
- name: Deploy to GitHub Releases

common.gradle

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,35 @@ publishing {
157157
version project.version
158158
}
159159
}
160+
160161
repositories {
161162
maven {
162163
name = 'Dist'
163164
url = gradle.rootProject.projectDir.absolutePath + '/dist/maven'
164165
}
166+
167+
// Uploading to Sonatype relies on the existence of 2 properties
168+
// (centralUsername and centralPassword)
169+
// which should be set using -P options on the command line.
170+
171+
maven {
172+
// for uploading release builds to the default repo in Sonatype's OSSRH staging area
173+
credentials {
174+
username = gradle.rootProject.hasProperty('centralUsername') ? centralUsername : 'Unknown user'
175+
password = gradle.rootProject.hasProperty('centralPassword') ? centralPassword : 'Unknown password'
176+
}
177+
name = 'Central'
178+
url = 'https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/'
179+
}
165180
maven {
181+
// for uploading snapshot builds to Sonatype's maven-snapshots repo
166182
credentials {
167-
username = gradle.rootProject.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user'
168-
password = gradle.rootProject.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password'
183+
username = gradle.rootProject.hasProperty('centralUsername') ? centralUsername : 'Unknown user'
184+
password = gradle.rootProject.hasProperty('centralPassword') ? centralPassword : 'Unknown password'
169185
}
170-
name = 'OSSRH'
171-
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2'
186+
name = 'SNAPSHOT'
187+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
172188
}
173-
maven {
174-
credentials {
175-
username = gradle.rootProject.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user'
176-
password = gradle.rootProject.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password'
177-
}
178-
name = 'SNAPSHOT'
179-
url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
180-
}
181189
}
182190
}
183191

uploadToCentral.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#! /bin/bash
2+
set -euo pipefail
3+
4+
## Upload a deployment
5+
## from the "org.jmonkeyengine" namespace in Sonatype's OSSRH staging area
6+
## to Sonatype's Central Publisher Portal
7+
## so the deployment can be tested and then published or dropped.
8+
9+
## IMPORTANT: The upload request must originate
10+
## from the IP address used to stage the deployment to the staging area!
11+
12+
# The required -p and -u flags on the command line
13+
# specify the password and username components of a "user token"
14+
# generated using the web interface at https://central.sonatype.com/account
15+
16+
while getopts p:u: flag
17+
do
18+
case "${flag}" in
19+
p) centralPassword=${OPTARG};;
20+
u) centralUsername=${OPTARG};;
21+
esac
22+
done
23+
24+
# Combine both components into a base64 "user token"
25+
# suitable for the Authorization header of a POST request:
26+
27+
token=$(printf %s:%s "${centralUsername}" "${centralPassword}" | base64)
28+
29+
# Send a POST request to upload the deployment:
30+
31+
server='ossrh-staging-api.central.sonatype.com'
32+
endpoint='/manual/upload/defaultRepository/org.jmonkeyengine'
33+
url="https://${server}${endpoint}"
34+
35+
statusCode=$(curl "${url}" \
36+
--no-progress-meter \
37+
--output postData1.txt \
38+
--write-out '%{response_code}' \
39+
--request POST \
40+
--header 'accept: */*' \
41+
--header "Authorization: Bearer ${token}" \
42+
--data '')
43+
44+
echo "Status code = ${statusCode}"
45+
echo 'Received data:'
46+
cat postData1.txt
47+
echo '[EOF]'
48+
49+
# Retry if the default repo isn't found (status=400).
50+
51+
if [ "${statusCode}" == "400" ]; then
52+
echo "Will retry after 30 seconds."
53+
sleep 30
54+
55+
statusCode2=$(curl "${url}" \
56+
--no-progress-meter \
57+
--output postData2.txt \
58+
--write-out '%{response_code}' \
59+
--request POST \
60+
--header 'accept: */*' \
61+
--header "Authorization: Bearer ${token}" \
62+
--data '')
63+
64+
echo "Status code = ${statusCode2}"
65+
echo 'Received data:'
66+
cat postData2.txt
67+
echo '[EOF]'
68+
fi

0 commit comments

Comments
 (0)