Skip to content

Commit 7c95711

Browse files
feeblefakiebrfrn169jnmt
authored
Backport to branch(3.15) : Use JReleaser to release artifacts in Maven Central (#2858)
Co-authored-by: Toshihiro Suzuki <[email protected]> Co-authored-by: Jun Nemoto <[email protected]>
1 parent 087b8b3 commit 7c95711

File tree

6 files changed

+92
-69
lines changed

6 files changed

+92
-69
lines changed

.github/workflows/release-snapshot.yaml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,28 @@ jobs:
3030
VERSION=$(./gradlew :core:properties -q | grep "version:" | awk '{print $2}')
3131
echo "version=${VERSION}" >> $GITHUB_OUTPUT
3232
33-
- name: Upload SNAPSHOT versions for scalardb, scalardb-schema-loader, and scalardb-integration-test to Maven Snapshot Repository
33+
- name: Prepare SNAPSHOT versions of artifacts in staging-deploy directories
3434
if: contains(steps.version.outputs.version, '-SNAPSHOT')
35-
run: |
36-
echo "${{secrets.SIGNING_SECRET_KEY_RING}}" | base64 -d > ~/.gradle/secring.gpg
37-
./gradlew publish \
38-
-Psigning.keyId="${{ secrets.SIGNING_KEY_ID }}" \
39-
-P'signing.password'="${{ secrets.SIGNING_PASSWORD }}" \
40-
-Psigning.secretKeyRingFile="$(echo ~/.gradle/secring.gpg)" \
41-
-PossrhUsername="${{ secrets.OSSRH_USERNAMAE }}" \
42-
-PossrhPassword="${{ secrets.OSSRH_PASSWORD }}"
35+
run: ./gradlew publish
36+
37+
- name: Upload SNAPSHOT versions of artifacts to Maven Snapshot repository
38+
if: contains(steps.version.outputs.version, '-SNAPSHOT')
39+
env:
40+
JRELEASER_NEXUS2_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
41+
JRELEASER_NEXUS2_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
42+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
43+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY }}
44+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_SECRET_KEY }}
45+
run: ./gradlew jreleaserDeploy
46+
47+
- name: Upload JReleaser outputs
48+
if: always()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: jreleaser-release
52+
path: |
53+
build/jreleaser/trace.log
54+
build/jreleaser/output.properties
4355
4456
- name: Login to GitHub Container Registry
4557
uses: docker/login-action@v3

.github/workflows/upload-artifacts.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ jobs:
4343
- name: Setup Gradle
4444
uses: gradle/actions/setup-gradle@v4
4545

46+
- name: Prepare artifacts in staging-deploy directories
47+
run: ./gradlew publish
48+
49+
- name: Upload artifacts to Maven Central Repository
50+
env:
51+
JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
52+
JRELEASER_MAVENCENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
53+
JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
54+
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PUBLIC_KEY }}
55+
JRELEASER_GPG_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_SECRET_KEY }}
56+
run: ./gradlew jreleaserDeploy
57+
58+
- name: Upload JReleaser outputs
59+
if: always()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: jreleaser-release
63+
path: |
64+
build/jreleaser/trace.log
65+
build/jreleaser/output.properties
66+
4667
- name: Login to GitHub Container Registry
4768
uses: docker/login-action@v3
4869
with:
@@ -56,13 +77,3 @@ jobs:
5677
- name: Push containers
5778
run: |
5879
docker push ghcr.io/scalar-labs/scalardb-schema-loader:${{ steps.version.outputs.version }}
59-
60-
- name: Upload scalardb, scalardb-schema-loader, and scalardb-integration-test to Maven Central Repository
61-
run: |
62-
echo "${{secrets.SIGNING_SECRET_KEY_RING}}" | base64 -d > ~/.gradle/secring.gpg
63-
./gradlew publish \
64-
-Psigning.keyId="${{ secrets.SIGNING_KEY_ID }}" \
65-
-P'signing.password'="${{ secrets.SIGNING_PASSWORD }}" \
66-
-Psigning.secretKeyRingFile="$(echo ~/.gradle/secring.gpg)" \
67-
-PossrhUsername="${{ secrets.OSSRH_USERNAMAE }}" \
68-
-PossrhPassword="${{ secrets.OSSRH_PASSWORD }}"

build.gradle

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
buildscript {
2-
repositories {
3-
maven {
4-
url 'https://plugins.gradle.org/m2/'
5-
}
6-
}
7-
dependencies {
8-
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.13.0'
9-
}
1+
plugins {
2+
id "com.diffplug.spotless" version "6.13.0"
3+
id "org.jreleaser" version "1.19.0"
4+
}
5+
6+
ext {
7+
projectGroup = 'com.scalar-labs'
8+
projectVersion = '3.15.5-SNAPSHOT'
109
}
1110

11+
group = projectGroup
12+
version = projectVersion
13+
1214
subprojects {
1315
apply plugin: 'java'
1416
apply plugin: 'eclipse'
@@ -18,7 +20,7 @@ subprojects {
1820
apply plugin: 'com.diffplug.spotless'
1921
apply plugin: 'com.scalar.db.jdk-configuration'
2022

21-
project.version = '3.15.5-SNAPSHOT'
23+
project.version = projectVersion
2224

2325
ext {
2426
guiceVersion = '5.1.0'
@@ -65,7 +67,7 @@ subprojects {
6567
testLogging.showStandardStreams = true
6668
}
6769

68-
group = "com.scalar-labs"
70+
group = projectGroup
6971

7072
java {
7173
withJavadocJar()
@@ -91,3 +93,37 @@ subprojects {
9193
}
9294
}
9395

96+
jreleaser {
97+
gitRootSearch = true
98+
99+
signing {
100+
active = 'ALWAYS'
101+
armored = true
102+
}
103+
104+
deploy {
105+
maven {
106+
def stagingRepositories = ['core/build/staging-deploy',
107+
'integration-test/build/staging-deploy',
108+
'schema-loader/build/staging-deploy']
109+
mavenCentral {
110+
sonatype {
111+
active = 'RELEASE'
112+
url = 'https://central.sonatype.com/api/v1/publisher'
113+
stagingRepositories.each { stagingRepository(it) }
114+
}
115+
}
116+
nexus2 {
117+
'snapshot-deploy' {
118+
active = 'SNAPSHOT'
119+
snapshotUrl = 'https://central.sonatype.com/repository/maven-snapshots/'
120+
applyMavenCentralRules = true
121+
snapshotSupported = true
122+
closeRepository = true
123+
releaseRepository = true
124+
stagingRepositories.each { stagingRepository(it) }
125+
}
126+
}
127+
}
128+
}
129+
}

core/build.gradle

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ plugins {
22
id 'com.github.spotbugs-base' version "${spotbugsPluginVersion}"
33
id 'net.ltgt.errorprone' version "${errorpronePluginVersion}"
44
id 'maven-publish'
5-
id 'signing'
65
id 'base'
76
}
87

@@ -352,18 +351,7 @@ publishing {
352351
}
353352
repositories {
354353
maven {
355-
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
356-
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
357-
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
358-
credentials {
359-
username = project.properties['ossrhUsername'] ?: ""
360-
password = project.properties['ossrhPassword'] ?: ""
361-
}
354+
url = layout.buildDirectory.dir('staging-deploy')
362355
}
363356
}
364357
}
365-
366-
signing {
367-
required { project.gradle.taskGraph.hasTask("publish") }
368-
sign publishing.publications.mavenJava
369-
}

integration-test/build.gradle

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ plugins {
22
id 'com.github.spotbugs' version "${spotbugsPluginVersion}"
33
id 'net.ltgt.errorprone' version "${errorpronePluginVersion}"
44
id 'maven-publish'
5-
id 'signing'
65
id 'base'
76
}
87

@@ -100,18 +99,7 @@ publishing {
10099
}
101100
repositories {
102101
maven {
103-
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
104-
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
105-
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
106-
credentials {
107-
username = project.properties['ossrhUsername'] ?: ""
108-
password = project.properties['ossrhPassword'] ?: ""
109-
}
102+
url = layout.buildDirectory.dir('staging-deploy')
110103
}
111104
}
112105
}
113-
114-
signing {
115-
required { project.gradle.taskGraph.hasTask("publish") }
116-
sign publishing.publications.mavenJava
117-
}

schema-loader/build.gradle

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ plugins {
33
id 'com.github.johnrengelman.shadow' version "${shadowPluginVersion}"
44
id 'com.github.spotbugs' version "${spotbugsPluginVersion}"
55
id 'maven-publish'
6-
id 'signing'
76
id 'base'
87
}
98

@@ -134,18 +133,7 @@ publishing {
134133
}
135134
repositories {
136135
maven {
137-
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
138-
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
139-
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
140-
credentials {
141-
username = project.properties['ossrhUsername'] ?: ""
142-
password = project.properties['ossrhPassword'] ?: ""
143-
}
136+
url = layout.buildDirectory.dir('staging-deploy')
144137
}
145138
}
146139
}
147-
148-
signing {
149-
required { project.gradle.taskGraph.hasTask("publish") }
150-
sign publishing.publications.mavenJava
151-
}

0 commit comments

Comments
 (0)