Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ci/release/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pipeline {
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
]) {
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
sshagent(['ed25519.Hibernate-CI.github.com']) {
// set release version
// update changelog from JIRA
// tags the version
Expand Down Expand Up @@ -211,7 +211,7 @@ pipeline {
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', 'jenkins.in.relation.to', 'hibernate-ci.frs.sourceforge.net']) {
sshagent(['ed25519.Hibernate-CI.github.com', 'jenkins.in.relation.to']) {
// performs documentation upload and Sonatype release
// push to github
withEnv([
Expand All @@ -237,7 +237,7 @@ pipeline {
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'] ) {
sshagent( ['ed25519.Hibernate-CI.github.com'] ) {
dir( '.release/hibernate.org' ) {
checkout scmGit(
branches: [[name: '*/production']],
Expand Down
3 changes: 3 additions & 0 deletions documentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def renderReferenceDocumentationTask = tasks.register( "renderReferenceDocumenta
"html-meta-version-family": versionFamily.get(),
)

// See https://docs.asciidoctor.org/gradle-plugin/latest/common-task-configuration/#choosing-an-execution-mode-for-asciidoctorj
executionMode = org.ysb33r.grolifant.api.core.jvm.ExecutionMode.JAVA_EXEC
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is a bonus 😄
we don't really need it for releases or anything ... but it helps with asciidoc building 🙂


dependsOn( tasks.named( "unpackTheme" ) )
}

Expand Down
8 changes: 8 additions & 0 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ publishing {
}
}
}

def releasePrepareTask = tasks.register("releasePrepare") {
description "Prepares all the artifacts and documentation for a JReleaser release."
group "Release"

// Create all the published artifacts (i.e. jars) and move them to the staging directory (for JReleaser):
dependsOn publishAllPublicationsToStagingRepository
}
252 changes: 6 additions & 246 deletions release/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,6 @@ final Directory documentationDir = project(":documentation").layout.buildDirecto
// Relative path on the static website where the documentation is located
final String docWebsiteRelativePath = "reactive/documentation/${projectVersion.family}"

def releaseChecksTask = tasks.register( "releaseChecks" ) {
description 'Checks and preparation for release'
group 'Release'

doFirst {
logger.lifecycle("Checking that the working tree is clean...")
String uncommittedFiles = executeGitCommand('status', '--porcelain')
if (!uncommittedFiles.isEmpty()) {
throw new GradleException(
"Cannot release because there are uncommitted or untracked files in the working tree.\n" +
"Commit or stash your changes first.\n" +
"Uncommitted files:\n " +
uncommittedFiles
)
}

String gitBranchLocal = project.hasProperty( 'gitBranch' ) && !project.property( 'gitBranch' ).isEmpty()
? project.property( 'gitBranch' )
: executeGitCommand( 'branch', '--show-current' ).trim()

String gitRemoteLocal
if ( project.hasProperty( 'gitRemote' ) && !project.property( 'gitRemote' ).isEmpty() ) {
gitRemoteLocal = project.property( 'gitRemote' )
}
else {
final String remotes = executeGitCommand( 'remote', 'show' ).trim()
final List<String> tokens = remotes.tokenize()
if ( tokens.size() != 1 ) {
throw new GradleException( "Could not determine `gitRemote` property for `releaseChecks` tasks." )
}
gitRemoteLocal = tokens.get( 0 )
}

project.ext {
gitBranch = gitBranchLocal
gitRemote = gitRemoteLocal
}

logger.lifecycle( "Switching to branch '${project.gitBranch}'..." )
executeGitCommand( 'checkout', project.gitBranch )

logger.lifecycle( "Checking that all commits are pushed..." )
String diffWithUpstream = executeGitCommand( 'diff', '@{u}' )
if ( !diffWithUpstream.isEmpty() ) {
throw new GradleException(
"Cannot perform `ciRelease` tasks because there are un-pushed local commits .\n" +
"Push your commits first."
)
}
}
}

/**
* Assembles all documentation into the {buildDir}/documentation directory.
*/
Expand All @@ -84,22 +32,9 @@ def assembleDocumentationTask = tasks.register( 'assembleDocumentation' ) {
}
assemble.dependsOn assembleDocumentationTask

def changeToReleaseVersionTask = tasks.register( 'changeToReleaseVersion' ) {
description 'Updates `gradle/version.properties` file to the specified release-version'
group 'Release'

dependsOn releaseChecksTask

doFirst {
logger.lifecycle( "Updating version-file to release-version : `${project.releaseVersion}`" )
updateVersionFile( "${project.releaseVersion}" )
}
}

def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
description "Update the documentation on the cloned static website"
dependsOn assembleDocumentationTask
mustRunAfter changeToReleaseVersion

// copy documentation outputs into target/documentation:
// * this is used in building the dist bundles
Expand All @@ -120,188 +55,13 @@ def updateDocumentationTask = tasks.register( 'updateDocumentation' ) {
}
}

def gitPreparationForReleaseTask = tasks.register( 'gitPreparationForRelease' ) {
dependsOn releaseChecksTask, changeToReleaseVersionTask
finalizedBy updateDocumentationTask

doLast {
logger.lifecycle( "Performing pre-steps Git commit : `${project.releaseVersion}`" )
executeGitCommand( 'add', '.' )
executeGitCommand( 'commit', '-m', "Update project version to : `${project.releaseVersion}`" )
}
}

def changeToDevelopmentVersionTask = tasks.register( 'changeToDevelopmentVersion' ) {
description 'Updates `gradle/version.properties` file to the specified development-version'
group 'Release'

dependsOn releaseChecksTask

doFirst {
logger.lifecycle( "Updating version-file to development-version : `${project.developmentVersion}`" )
updateVersionFile( "${project.developmentVersion}" )
}
}

def releasePreparePostGitTask = tasks.register( 'gitTasksAfterRelease' ) {
dependsOn changeToDevelopmentVersionTask

doLast {
if ( project.createTag ) {
logger.lifecycle( "Tagging release : `${project.releaseTag}`..." )
executeGitCommand( 'tag', '-a', project.releaseTag, '-m', "Release $project.projectVersion" )
}

logger.lifecycle( "Performing post-steps Git commit : `${project.releaseVersion}`" )
executeGitCommand( 'add', '.' )
executeGitCommand( 'commit', '-m', "Update project version to : `${project.developmentVersion}`" )
}
}

void updateVersionFile(var version) {
logger.lifecycle( "Updating `gradle/version.properties` version to `${version}`" )
project.versionFile.text = "projectVersion=${version}"
project.version = version
}

def publishReleaseArtifactsTask = tasks.register( 'publishReleaseArtifacts' ) {
dependsOn updateDocumentationTask

mustRunAfter gitPreparationForReleaseTask
}

def releasePerformPostGitTask = tasks.register( 'gitTasksAfterReleasePerform' ) {

doLast {
if ( project.createTag ) {
logger.lifecycle( "Pushing branch and tag to remote `${project.gitRemote}`..." )
executeGitCommand( 'push', '--atomic', project.gitRemote, project.gitBranch, project.releaseTag )
}
else {
logger.lifecycle( "Pushing branch to remote `${project.gitRemote}`..." )
executeGitCommand( 'push', project.gitRemote, project.gitBranch )
}
}
}

def releasePrepareTask = tasks.register( "releasePrepare" ) {
description "On a local checkout, performs all the changes required for the release, website updates included"
group "Release"

dependsOn gitPreparationForReleaseTask

finalizedBy releasePreparePostGitTask
}

def releasePerformTask = tasks.register( 'releasePerform' ) {
group 'Release'
description 'Performs a release on local check-out, including updating changelog and '

dependsOn publishReleaseArtifactsTask

finalizedBy releasePerformPostGitTask
}

/*
* Release everything
*/
def releaseTask = tasks.register( 'release' ) {
description 'Performs a release on local check-out'
group 'Release'

dependsOn releasePrepareTask
dependsOn releasePerformTask
}

def ciReleaseTask = tasks.register( 'ciRelease' ) {
description "Triggers the release on CI: creates commits to change the version (release, then development), creates a tag, pushes everything. Then CI will take over and perform the release."
description "Prepares all the artifacts and documentation for a JReleaser release."
group "Release"

dependsOn releaseTask
}

static String executeGitCommand(Object ... subcommand){
List<Object> command = ['git']
Collections.addAll( command, subcommand )
def proc = command.execute()
def code = proc.waitFor()
def stdout = inputStreamToString( proc.getInputStream() )
def stderr = inputStreamToString( proc.getErrorStream() )
if ( code != 0 ) {
throw new GradleException( "An error occurred while executing " + command + "\n\nstdout:\n" + stdout + "\n\nstderr:\n" + stderr )
}
return stdout
}

static String inputStreamToString(InputStream inputStream) {
inputStream.withCloseable { ins ->
new BufferedInputStream(ins).withCloseable { bis ->
new ByteArrayOutputStream().withCloseable { buf ->
int result = bis.read()
while (result != -1) {
buf.write((byte) result)
result = bis.read()
}
return buf.toString(StandardCharsets.UTF_8.name())
}
}
}
}

gradle.getTaskGraph().whenReady { tg->
if ( ( tg.hasTask( project.tasks.releasePrepare ) || tg.hasTask( project.tasks.releasePerform ) )
&& ! project.getGradle().getStartParameter().isDryRun() ) {
String releaseVersionLocal
String developmentVersionLocal

def console = tg.hasTask( project.tasks.release ) && !tg.hasTask( project.tasks.ciRelease )
? System.console()
: null

if (project.hasProperty('releaseVersion')) {
releaseVersionLocal = project.property('releaseVersion')
}
else {
if (console) {
// prompt for `releaseVersion`
releaseVersionLocal = console.readLine('> Enter the release version: ')
}
else {
throw new GradleException(
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
)
}
}

if (project.hasProperty('developmentVersion')) {
developmentVersionLocal = project.property('developmentVersion')
}
else {
if (console) {
// prompt for `developmentVersion`
developmentVersionLocal = console.readLine('> Enter the next development version: ')
}
else {
throw new GradleException(
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
)
}
}

assert releaseVersionLocal != null && developmentVersionLocal != null

// set up information for the release-related tasks
project.ext {
releaseVersion = releaseVersionLocal
developmentVersion = developmentVersionLocal
createTag = !project.hasProperty('noTag')
releaseTag = project.createTag ? determineReleaseTag(releaseVersionLocal) : ''
}
}
}

static String determineReleaseTag(String releaseVersion) {
return releaseVersion.endsWith( '.Final' )
? releaseVersion.replace( ".Final", "" )
: releaseVersion
// Render the Documentation/Javadocs and move them to the staging directory (for JReleaser):
dependsOn updateDocumentationTask
// Create all the published artifacts (i.e. jars) and move them to the staging directory (for JReleaser):
// this one is defined in the publish.gradle
// dependsOn project.getTasksByName(publishAllPublicationsToStagingRepository, false)
}
Loading