Skip to content

Commit 5df6c58

Browse files
committed
[#2027] Use env-vars for passing secrets used during release
1 parent 62bb1eb commit 5df6c58

File tree

4 files changed

+27
-48
lines changed

4 files changed

+27
-48
lines changed

build.gradle

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ group = "org.hibernate.reactive"
1212
// leverage the ProjectVersion which comes from the `local.versions` plugin
1313
version = project.projectVersion.fullName
1414

15-
ext {
16-
if ( !project.hasProperty( 'hibernatePublishUsername' ) ) {
17-
hibernatePublishUsername = null
18-
}
19-
if ( !project.hasProperty( 'hibernatePublishPassword' ) ) {
20-
hibernatePublishPassword = null
21-
}
22-
}
23-
2415
// Versions which need to be aligned across modules; this also
2516
// allows overriding the build using a parameter, which can be
2617
// useful to monitor compatibility for upcoming versions on CI:
@@ -39,15 +30,10 @@ ext {
3930
logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion
4031
}
4132

42-
// To release, see task ciRelease in release/build.gradle
43-
// To publish on Sonatype (Maven Central):
44-
// ./gradlew publishToSonatype closeAndReleaseStagingRepository -PhibernatePublishUsername="<YOUR USERNAME>" -PhibernatePublishPassword="<YOUR PASSWORD>"
33+
// Publishing to Sonatype (Maven Central):
4534
nexusPublishing {
4635
repositories {
47-
sonatype {
48-
username = project.hibernatePublishUsername
49-
password = project.hibernatePublishPassword
50-
}
36+
sonatype()
5137
}
5238
}
5339

ci/release/Jenkinsfile

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,18 @@ pipeline {
165165
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
166166
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
167167
]) {
168-
withCredentials([
169-
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'),
170-
usernamePassword(credentialsId: 'gradle-plugin-portal-api-key', passwordVariable: 'PLUGIN_PORTAL_PASSWORD', usernameVariable: 'PLUGIN_PORTAL_USERNAME'),
171-
file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'),
172-
string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE')
173-
]) {
174-
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
175-
// set release version
176-
// update changelog from JIRA
177-
// tags the version
178-
// changes the version to the provided development version
179-
withEnv([
180-
"BRANCH=${env.GIT_BRANCH}",
181-
// Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace
182-
"GRADLE_OPTS=-Dorg.gradle.jvmargs='-Dlog4j2.disableJmx -Xmx4g -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8'"
183-
]) {
184-
sh ".release/scripts/prepare-release.sh ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION}"
185-
}
168+
169+
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
170+
// set release version
171+
// update changelog from JIRA
172+
// tags the version
173+
// changes the version to the provided development version
174+
withEnv([
175+
"BRANCH=${env.GIT_BRANCH}",
176+
// Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace
177+
"GRADLE_OPTS=-Dorg.gradle.jvmargs='-Dlog4j2.disableJmx -Xmx4g -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8'"
178+
]) {
179+
sh ".release/scripts/prepare-release.sh ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION}"
186180
}
187181
}
188182
}
@@ -199,10 +193,10 @@ pipeline {
199193
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
200194
]) {
201195
withCredentials([
202-
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'),
203-
usernamePassword(credentialsId: 'gradle-plugin-portal-api-key', passwordVariable: 'PLUGIN_PORTAL_PASSWORD', usernameVariable: 'PLUGIN_PORTAL_USERNAME'),
204-
file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'),
205-
string(credentialsId: 'release.gpg.passphrase', variable: 'RELEASE_GPG_PASSPHRASE')
196+
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
197+
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername'),
198+
file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'),
199+
string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE')
206200
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
207201
]) {
208202
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {

ci/snapshot-publish.Jenkinsfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ pipeline {
3131
stage('Publish') {
3232
steps {
3333
withCredentials([
34-
usernamePassword(credentialsId: 'ossrh.sonatype.org', usernameVariable: 'hibernatePublishUsername', passwordVariable: 'hibernatePublishPassword'),
34+
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
35+
usernamePassword(credentialsId: 'ossrh.sonatype.org', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword'),
3536
file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'),
3637
string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE')
3738
]) {
38-
sh '''./gradlew clean publish \
39-
-PhibernatePublishUsername=$hibernatePublishUsername \
40-
-PhibernatePublishPassword=$hibernatePublishPassword \
41-
--no-scan \
42-
'''
39+
sh "./gradlew clean publish --no-scan"
4340
}
4441
}
4542
}

publish.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ javadoc {
3636

3737
publishing {
3838
publications {
39-
publishedArtifacts(MavenPublication) {
39+
register( "publishedArtifacts", MavenPublication) {
4040
from components.java
4141

4242
pom {
@@ -94,19 +94,21 @@ gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
9494
List<Sign> signingTasks = []
9595

9696
graph.allTasks.each {task ->
97-
logger.lifecycle( "Checking task : $task" )
9897
if ( task instanceof Sign ) {
99-
logger.lifecycle( " - Task is Sign" )
10098
signingTasks.add( task )
10199
wasSigningRequested = true
102100
}
103101
else if ( task instanceof PublishToMavenRepository ) {
104-
logger.lifecycle( " - Task is PublishToMavenRepository" )
105102
wasPublishingRequested = true
106103
}
107104
}
108105

109106
if ( wasPublishingRequested ) {
107+
def ossrhUser = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypeUsername" )
108+
def ossrhPass = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypePassword" )
109+
if ( ossrhUser == null || ossrhPass == null ) {
110+
throw new RuntimeException( "Cannot perform publishing to OSSRH without credentials." )
111+
}
110112
logger.lifecycle "Publishing groupId: '" + project.group + "', version: '" + project.version + "'"
111113
}
112114

0 commit comments

Comments
 (0)