2023-09-21 12:20:21 -04:00
#! /usr/bin/groovy
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
/*
* See https://github.com/hibernate/hibernate-jenkins-pipeline-helpers
*/
2024-06-18 03:55:39 -04:00
@Library('hibernate-jenkins-pipeline-helpers@1.17') _
2024-06-12 05:24:44 -04:00
import org.hibernate.jenkins.pipeline.helpers.version.Version
2023-09-21 12:20:21 -04:00
2024-06-13 06:10:10 -04:00
// --------------------------------------------
// Global build configuration
env.PROJECT = "orm"
env.JIRA_KEY = "HHH"
def RELEASE_ON_PUSH = false // Set to `true` *only* on branches where you want a release on each push.
2024-06-13 06:14:36 -04:00
print "INFO: env.PROJECT = ${env.PROJECT}"
print "INFO: env.JIRA_KEY = ${env.JIRA_KEY}"
print "INFO: RELEASE_ON_PUSH = ${RELEASE_ON_PUSH}"
2024-06-13 06:10:10 -04:00
// --------------------------------------------
// Build conditions
2024-06-12 05:41:15 -04:00
2023-09-21 12:20:21 -04:00
// Avoid running the pipeline on branch indexing
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
print "INFO: Build skipped due to trigger being Branch Indexing"
2023-10-06 09:01:00 -04:00
currentBuild.result = 'NOT_BUILT'
2023-09-21 12:20:21 -04:00
return
}
2024-06-13 06:10:10 -04:00
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
// Only do automatic release on branches where we opted in
if ( !manualRelease && !RELEASE_ON_PUSH ) {
print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_PUSH in ci/release/Jenkinsfile"
currentBuild.result = 'NOT_BUILT'
return
}
// --------------------------------------------
// Reusable methods
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
2023-09-21 12:20:21 -04:00
pipeline {
agent {
label 'Worker&&Containers'
}
tools {
2024-06-14 10:06:25 -04:00
jdk 'OpenJDK 17 Latest'
2023-09-21 12:20:21 -04:00
}
options {
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10')
rateLimitBuilds(throttle: [count: 1, durationName: 'day', userBoost: true])
disableConcurrentBuilds(abortPrevious: false)
preserveStashes()
}
parameters {
string(
name: 'RELEASE_VERSION',
defaultValue: '',
2024-06-12 05:33:55 -04:00
description: 'The version to be released, e.g. 6.2.1.Final. Mandatory for manual releases, to prevent mistakes.',
2023-09-21 12:20:21 -04:00
trim: true
)
string(
name: 'DEVELOPMENT_VERSION',
defaultValue: '',
2024-06-12 05:33:55 -04:00
description: 'The next version to be used after the release, e.g. 6.2.2-SNAPSHOT. If not set, determined automatically from the release version.',
2023-09-21 12:20:21 -04:00
trim: true
)
booleanParam(
name: 'RELEASE_DRY_RUN',
defaultValue: false,
description: 'If true, just simulate the release, without pushing any commits or tags, and without uploading any artifacts or documentation.'
)
}
stages {
stage('Release check') {
steps {
script {
2024-06-12 05:41:15 -04:00
checkoutReleaseScripts()
2024-06-12 05:33:55 -04:00
2024-06-12 05:24:44 -04:00
def currentVersion = Version.parseDevelopmentVersion( sh(
2023-09-21 12:20:21 -04:00
script: ".release/scripts/determine-current-version.sh ${env.PROJECT}",
returnStdout: true
2024-06-12 05:24:44 -04:00
).trim() )
2024-06-12 05:11:20 -04:00
echo "Workspace version: ${currentVersion}"
2024-06-12 05:33:55 -04:00
2024-06-12 05:24:44 -04:00
def releaseVersion
def developmentVersion
2023-09-21 12:20:21 -04:00
2024-06-12 05:33:55 -04:00
if ( manualRelease ) {
echo "Release was requested manually"
if ( !params.RELEASE_VERSION ) {
throw new IllegalArgumentException( 'Missing value for parameter RELEASE_VERSION. This parameter must be set explicitly to prevent mistakes.' )
}
releaseVersion = Version.parseReleaseVersion( params.RELEASE_VERSION )
2024-06-14 11:26:34 -04:00
if ( !releaseVersion.toString().startsWith( currentVersion.family + '.' ) ) {
2024-06-12 05:33:55 -04:00
throw new IllegalArgumentException( "RELEASE_VERSION = $releaseVersion, which is different from the family of CURRENT_VERSION = $currentVersion. Did you make a mistake?" )
}
}
else {
echo "Release was triggered automatically"
2024-06-12 05:54:34 -04:00
// Avoid doing an automatic release for commits from a release
2024-06-12 05:33:55 -04:00
def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true)
def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true)
if (lastCommitter == 'Hibernate-CI' && secondLastCommitter == 'Hibernate-CI') {
2024-06-12 05:54:34 -04:00
print "INFO: Automatic release skipped because last commits were for the previous release"
2024-06-12 05:33:55 -04:00
currentBuild.result = 'ABORTED'
return
}
2024-06-12 05:24:44 -04:00
releaseVersion = Version.parseReleaseVersion( sh(
2024-06-12 05:11:20 -04:00
script: ".release/scripts/determine-release-version.sh ${currentVersion}",
2023-09-21 12:20:21 -04:00
returnStdout: true
2024-06-12 05:24:44 -04:00
).trim() )
2023-09-21 12:20:21 -04:00
}
2024-06-12 05:24:44 -04:00
echo "Release version: ${releaseVersion}"
2024-06-12 05:11:20 -04:00
2024-06-12 05:33:55 -04:00
if ( !params.DEVELOPMENT_VERSION ) {
2024-06-12 05:24:44 -04:00
developmentVersion = Version.parseDevelopmentVersion( sh(
script: ".release/scripts/determine-development-version.sh ${releaseVersion}",
2023-09-21 12:20:21 -04:00
returnStdout: true
2024-06-12 05:24:44 -04:00
).trim() )
2023-09-21 12:20:21 -04:00
}
else {
2024-06-12 05:24:44 -04:00
developmentVersion = Version.parseDevelopmentVersion( params.DEVELOPMENT_VERSION )
2023-09-21 12:20:21 -04:00
}
2024-06-12 05:24:44 -04:00
echo "Development version: ${developmentVersion}"
2024-06-12 05:11:20 -04:00
2024-06-12 05:24:44 -04:00
env.RELEASE_VERSION = releaseVersion.toString()
env.DEVELOPMENT_VERSION = developmentVersion.toString()
2023-09-21 12:20:21 -04:00
env.SCRIPT_OPTIONS = params.RELEASE_DRY_RUN ? "-d" : ""
// Determine version id to check if Jira version exists
2024-06-18 03:55:39 -04:00
sh ".release/scripts/determine-jira-version-id.sh ${env.JIRA_KEY} ${releaseVersion.withoutFinalQualifier}"
2023-09-21 12:20:21 -04:00
}
}
}
stage('Release prepare') {
steps {
script {
2024-06-12 05:41:15 -04:00
checkoutReleaseScripts()
configFileProvider([
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
]) {
2023-09-21 12:20:21 -04:00
withCredentials([
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'),
usernamePassword(credentialsId: 'gradle-plugin-portal-api-key', passwordVariable: 'PLUGIN_PORTAL_PASSWORD', usernameVariable: 'PLUGIN_PORTAL_USERNAME'),
file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'),
string(credentialsId: 'release.gpg.passphrase', variable: 'RELEASE_GPG_PASSPHRASE')
]) {
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
// set release version
// update changelog from JIRA
// tags the version
// changes the version to the provided development version
2024-08-09 10:22:53 -04:00
withEnv([
"BRANCH=${env.GIT_BRANCH}",
// Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace
2024-08-09 12:04:24 -04:00
"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'"
2024-08-09 10:22:53 -04:00
]) {
2024-06-14 11:55:54 -04:00
sh ".release/scripts/prepare-release.sh ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION}"
}
2023-09-21 12:20:21 -04:00
}
}
}
}
}
}
stage('Publish release') {
steps {
script {
2024-06-12 05:41:15 -04:00
checkoutReleaseScripts()
configFileProvider([
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
]) {
2023-09-21 12:20:21 -04:00
withCredentials([
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'),
usernamePassword(credentialsId: 'gradle-plugin-portal-api-key', passwordVariable: 'PLUGIN_PORTAL_PASSWORD', usernameVariable: 'PLUGIN_PORTAL_USERNAME'),
2023-10-04 13:03:15 -04:00
file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'),
2023-10-04 18:44:02 -04:00
string(credentialsId: 'release.gpg.passphrase', variable: 'RELEASE_GPG_PASSPHRASE'),
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
2023-09-21 12:20:21 -04:00
]) {
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
// performs documentation upload and Sonatype release
// push to github
2024-06-14 12:48:39 -04:00
sh ".release/scripts/publish.sh ${env.SCRIPT_OPTIONS} ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION} ${env.GIT_BRANCH}"
2023-09-21 12:20:21 -04:00
}
}
}
}
}
}
stage('Website release') {
steps {
script {
2024-06-12 05:41:15 -04:00
checkoutReleaseScripts()
configFileProvider([
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
]) {
2023-10-04 18:44:02 -04:00
withCredentials([
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
]) {
sshagent( ['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net'] ) {
dir( '.release/hibernate.org' ) {
checkout scmGit(
branches: [[name: '*/production']],
extensions: [],
userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com', url: 'https://github.com/hibernate/hibernate.org.git']]
)
2023-10-04 18:44:02 -04:00
sh "../scripts/website-release.sh ${env.SCRIPT_OPTIONS} ${env.PROJECT} ${env.RELEASE_VERSION}"
2023-10-04 18:44:02 -04:00
}
2023-09-21 12:20:21 -04:00
}
}
}
}
}
}
stage('GitHub release') {
steps {
script {
2024-06-12 05:41:15 -04:00
checkoutReleaseScripts()
2023-09-21 12:20:21 -04:00
withCredentials([string(credentialsId: 'Hibernate-CI.github.com', variable: 'GITHUB_API_TOKEN')]) {
sh ".release/scripts/github-release.sh ${env.SCRIPT_OPTIONS} ${env.PROJECT} ${env.RELEASE_VERSION}"
}
}
}
}
}
post {
always {
configFileProvider([configFile(fileId: 'job-configuration.yaml', variable: 'JOB_CONFIGURATION_FILE')]) {
notifyBuildResult maintainers: (String) readYaml(file: env.JOB_CONFIGURATION_FILE).notification?.email?.recipients
}
}
}
}