From bcec90e0fc6cd707d3ef65bc48cf2f11d8065e5d Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Fri, 25 Apr 2025 16:45:33 +0200 Subject: [PATCH] [#2222] Add a simple JReleaser configuration --- .gitignore | 3 -- .release/.gitignore | 3 ++ build.gradle | 7 --- ci/release/Jenkinsfile | 28 ++++++---- ci/snapshot-publish.Jenkinsfile | 38 ++++++++++--- jreleaser.yml | 59 ++++++++++++++++++++ publish.gradle | 96 ++------------------------------- release/build.gradle | 1 - 8 files changed, 114 insertions(+), 121 deletions(-) create mode 100644 .release/.gitignore create mode 100644 jreleaser.yml diff --git a/.gitignore b/.gitignore index 8016117ce..750319d47 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,3 @@ bin # Vim *.swp *.swo - -# Release scripts downloaded from hibernate/hibernate-release-scripts -.release diff --git a/.release/.gitignore b/.release/.gitignore new file mode 100644 index 000000000..cdd9a17d6 --- /dev/null +++ b/.release/.gitignore @@ -0,0 +1,3 @@ +# The folder into which we checkout our release scripts into +* +!.gitignore \ No newline at end of file diff --git a/build.gradle b/build.gradle index c7ad6918c..4c5235a9a 100644 --- a/build.gradle +++ b/build.gradle @@ -30,13 +30,6 @@ ext { logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion } -// Publishing to Sonatype (Maven Central): -nexusPublishing { - repositories { - sonatype() - } -} - subprojects { apply plugin: 'java-library' apply plugin: 'com.diffplug.spotless' diff --git a/ci/release/Jenkinsfile b/ci/release/Jenkinsfile index d365436ab..4ae62e3f3 100644 --- a/ci/release/Jenkinsfile +++ b/ci/release/Jenkinsfile @@ -119,8 +119,10 @@ pipeline { echo "Release was triggered automatically" // Avoid doing an automatic release for commits from a release - def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true) - def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true) + def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true).trim() + def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true).trim() + echo "Last two commits were performed by '${lastCommitter}'/'${secondLastCommitter}'." + if (lastCommitter == 'Hibernate-CI' && secondLastCommitter == 'Hibernate-CI') { print "INFO: Automatic release skipped because last commits were for the previous release" currentBuild.result = 'ABORTED' @@ -149,6 +151,7 @@ pipeline { env.DEVELOPMENT_VERSION = developmentVersion.toString() // Dry run is not supported at the moment env.SCRIPT_OPTIONS = params.RELEASE_DRY_RUN ? "-d" : "" + env.JRELEASER_DRY_RUN = true // Determine version id to check if Jira version exists // This step doesn't work for Hibernate Reactive (the project has been created with a different type on JIRA) @@ -172,11 +175,10 @@ pipeline { // tags the version // changes the version to the provided development version withEnv([ - "BRANCH=${env.GIT_BRANCH}", // Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace "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'" ]) { - sh ".release/scripts/prepare-release.sh ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION}" + sh ".release/scripts/prepare-release.sh -b ${env.GIT_BRANCH} -d ${env.DEVELOPMENT_VERSION} ${env.PROJECT} ${env.RELEASE_VERSION}" } } } @@ -193,11 +195,17 @@ pipeline { configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts") ]) { withCredentials([ - // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh - usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername'), - file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'), - string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE'), - gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default') + // TODO: Once we switch to maven-central publishing (from nexus2) we need to add a new credentials + // to use the following env variable names to set the user/password: + // - JRELEASER_MAVENCENTRAL_USERNAME + // - JRELEASER_MAVENCENTRAL_TOKEN + // Also use the new `credentialsId` for Maven Central, e.g.: + // usernamePassword(credentialsId: '???????', passwordVariable: 'JRELEASER_MAVENCENTRAL_TOKEN', usernameVariable: 'JRELEASER_MAVENCENTRAL_USERNAME'), + usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'JRELEASER_NEXUS2_PASSWORD', usernameVariable: 'JRELEASER_NEXUS2_USERNAME'), + gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default'), + file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'), + string(credentialsId: 'release.gpg.passphrase', variable: 'JRELEASER_GPG_PASSPHRASE'), + string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN') ]) { sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) { // performs documentation upload and Sonatype release @@ -217,4 +225,4 @@ pipeline { } } } -} \ No newline at end of file +} diff --git a/ci/snapshot-publish.Jenkinsfile b/ci/snapshot-publish.Jenkinsfile index 07fa844c6..59a97eeee 100644 --- a/ci/snapshot-publish.Jenkinsfile +++ b/ci/snapshot-publish.Jenkinsfile @@ -10,6 +10,14 @@ if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) { return } +def checkoutReleaseScripts() { + dir('.release/scripts') { + checkout scmGit(branches: [[name: '*/main']], extensions: [], + userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com', + url: 'https://github.com/hibernate/hibernate-release-scripts.git']]) + } +} + pipeline { agent { label 'Release' @@ -30,13 +38,27 @@ pipeline { } stage('Publish') { steps { - withCredentials([ - // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh - usernamePassword(credentialsId: 'ossrh.sonatype.org', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword'), - file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'), - string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE') - ]) { - sh "./gradlew clean publish --no-scan" + script { + withCredentials([ + // https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh + // TODO: Once we switch to maven-central publishing (from nexus2) we need to add a new credentials + // to use the following env variable names to set the user/password: + // - JRELEASER_MAVENCENTRAL_USERNAME + // - JRELEASER_MAVENCENTRAL_TOKEN + // Also use the new `credentialsId` for Maven Central, e.g.: + // usernamePassword(credentialsId: '???????', passwordVariable: 'JRELEASER_MAVENCENTRAL_TOKEN', usernameVariable: 'JRELEASER_MAVENCENTRAL_USERNAME'), + usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'JRELEASER_NEXUS2_PASSWORD', usernameVariable: 'JRELEASER_NEXUS2_USERNAME'), + gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default'), + string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN') + ]) { + checkoutReleaseScripts() + def version = sh( + script: ".release/scripts/determine-current-version.sh orm", + returnStdout: true + ).trim() + echo "Current version: '${version}'" + sh "bash -xe .release/scripts/snapshot-deploy.sh reactive ${version}" + } } } } @@ -48,4 +70,4 @@ pipeline { } } } -} \ No newline at end of file +} diff --git a/jreleaser.yml b/jreleaser.yml new file mode 100644 index 000000000..c3eeec649 --- /dev/null +++ b/jreleaser.yml @@ -0,0 +1,59 @@ +project: + languages: + java: + groupId: org.hibernate.reactive + +release: + github: + skipTag: true + skipRelease: true + tagName: '{{projectVersion}}' + +# File signing is always active +signing: + mode: COMMAND + active: RELEASE + armored: true + +deploy: + maven: + # TODO: Remove the entire nexus2 section when switching to maven central publishing (see below): + nexus2: + maven-central: + active: RELEASE + url: https://oss.sonatype.org/service/local + snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/ + closeRepository: true + releaseRepository: false + stagingRepositories: + - build/staging-deploy/maven + maven-central-snapshot: + active: SNAPSHOT + url: https://oss.sonatype.org/service/local + snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/ + closeRepository: true + releaseRepository: true + javadocJar: false + sign: false + stagingRepositories: + - build/staging-deploy/maven + mavenCentral: + maven-central: + # TODO: Change to RELEASE once switching to Maven-Central: + # Note, this is an untested configuration, hence might need further adjustments + active: NEVER + url: https://central.sonatype.com/api/v1/publisher + snapshotSupported: false + applyMavenCentralRules: true + stagingRepositories: + - build/staging-deploy/maven + maven-central-snapshot: + # TODO: Change to SNAPSHOT once switching to Maven-Central: + active: NEVER + url: https://central.sonatype.com/api/v1/publisher + snapshotSupported: true + applyMavenCentralRules: true + javadocJar: false + sign: false + stagingRepositories: + - build/staging-deploy/maven diff --git a/publish.gradle b/publish.gradle index 977092d9a..201b67a8a 100644 --- a/publish.gradle +++ b/publish.gradle @@ -1,6 +1,5 @@ apply plugin: 'java' apply plugin: 'maven-publish' -apply plugin: 'signing' // Java / publishing @@ -75,97 +74,10 @@ publishing { } } } -} - - -// Signing - -var signingExtension = project.getExtensions().getByType(SigningExtension) as SigningExtension - -var publishingExtension = project.getExtensions().getByType(PublishingExtension) as PublishingExtension -signingExtension.sign publishingExtension.publications.publishedArtifacts - -var signingKey = resolveSigningKey() -var signingPassphrase = resolveSigningPassphrase() -signingExtension.useInMemoryPgpKeys(signingKey, signingPassphrase) - -gradle.taskGraph.whenReady { TaskExecutionGraph graph -> - boolean wasPublishingRequested = false - - graph.allTasks.each {task -> - if ( task instanceof PublishToMavenRepository ) { - logger.lifecycle( "Found PublishToMavenRepository task : {}", task.path ) - wasPublishingRequested = true + repositories { + maven { + name = "staging" + url = rootProject.layout.buildDirectory.dir("staging-deploy${File.separator}maven") } } - - if ( wasPublishingRequested ) { - def publishUser = resolvePublishUser() - def publishPass = resolvePublishPass() - if ( publishUser == null || publishPass == null ) { - throw new RuntimeException( "Cannot perform publishing to OSSRH without credentials." ) - } - - logger.lifecycle "Publishing {} : {} : {}", project.group, project.name, project.version - - // require signing if publishing to OSSRH - signingExtension.required = true - } - else if ( signingKey == null || signingPassphrase == null ) { - tasks.withType( Sign ).each { t-> t.enabled = false } - } } - - -static String resolveSigningKey() { - var key = System.getenv().get( "SIGNING_GPG_PRIVATE_KEY" ) - if ( key != null ) { - return key - } - - var keyFile = System.getenv().get( "SIGNING_GPG_PRIVATE_KEY_PATH" ) - if ( keyFile != null ) { - return new File( keyFile ).text - } - - return null -} - -static String resolveSigningPassphrase() { - return System.getenv().get( "SIGNING_GPG_PASSPHRASE" ) -} - -String resolvePublishUser() { - var envVar = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypeUsername" ) - if ( envVar != null ) { - return envVar - } - - def projectProp = projectPropOrNull( "sonatypeUsername" ) - if ( projectProp != null ) { - return projectProp - } - - return null -} - -String resolvePublishPass() { - var envVar = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypePassword" ) - if ( envVar != null ) { - return envVar - } - - def projectProp = projectPropOrNull( "sonatypePassword" ) - if ( projectProp != null ) { - return projectProp - } - - return null -} - -String projectPropOrNull(String name) { - if ( project.hasProperty( name ) ) { - return project.findProperty( name ) - } - return null; -} \ No newline at end of file diff --git a/release/build.gradle b/release/build.gradle index 2b507a9a2..690534750 100644 --- a/release/build.gradle +++ b/release/build.gradle @@ -236,7 +236,6 @@ void updateVersionFile(var version) { def publishReleaseArtifactsTask = tasks.register( 'publishReleaseArtifacts' ) { dependsOn uploadDocumentationTask - dependsOn ":hibernate-reactive-core:publishToSonatype" mustRunAfter gitPreparationForReleaseTask }