Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Aug 29, 2024
1 parent dee7b6e commit 6c14f64
Showing 1 changed file with 70 additions and 27 deletions.
97 changes: 70 additions & 27 deletions release/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ def publishDocumentationTask = tasks.register( 'publishDocumentation' ) {
}
}

def releasePrepareTask = tasks.register( "releasePrepare" ) {
description "Performs release preparations on local check-out, including updating changelog"
group "Release"
dependsOn commitDocChangesTask
def createTagTask = tasks.register( 'createTag' ) {
description "Create local tag"

doFirst {
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
throw new GradleException(
"Task 'releasePrepare' requires all of the following properties to be set:"
"Task 'createTag' requires all of the following properties to be set:"
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
)
}
Expand All @@ -147,25 +145,73 @@ def releasePrepareTask = tasks.register( "releasePrepare" ) {
logger.lifecycle( "Checking that all commits are pushed..." )
String diffWithUpstream = executeGitCommand( 'diff', '@{u}' )
if ( !diffWithUpstream.isEmpty() ) {
throw new GradleException(
"Cannot release because there are commits on the branch to release that haven't been pushed yet."
+ "\nPush your commits to the branch to release first."
)
throw new GradleException( "There are commits on the branch to release that haven't been pushed yet" )
}

logger.lifecycle( "Adding commit to update version to '${project.releaseVersion}'..." )
logger.lifecycle( "Commit version update to '${project.releaseVersion}'..." )
project.projectVersionFile.text = "projectVersion=${project.releaseVersion}"
executeGitCommand( 'add', '.' )
executeGitCommand( 'commit', '-m', project.releaseVersion )

String tag = project.releaseVersion
if ( tag.endsWith( ".Final" ) ) {
tag = tag.replace( ".Final", "" )
}
logger.lifecycle( "Tagging '${tag}'..." )
executeGitCommand( 'tag', '-a', '-m', "Release ${project.releaseVersion}", tag )
}
}

/*
* Release everything
*/
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."
def updateVersionsTask = tasks.register( "updateVersions" ) {
description "Update the release and development version, commit the changes, and create the tag"
group "Release"
dependsOn createTagTask

doFirst {
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
throw new GradleException(
"Task 'releasePrepare' requires all of the following properties to be set:"
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
)
}
}

doLast {
logger.lifecycle( "Checking that the working tree is clean..." )
String uncommittedFiles = executeGitCommand( 'status', '--porcelain' )
if ( !uncommittedFiles.isEmpty() ) {
throw new GradleException(
"Cannot update the version because there are uncommitted changes in the working tree."
+ "\nUncommitted files:\n" + uncommittedFiles
)
}

logger.lifecycle( "Adding commit to update version to '${project.developmentVersion}'..." )
project.projectVersionFile.text = "projectVersion=${project.developmentVersion}"
executeGitCommand( 'add', '.' )
executeGitCommand( 'commit', '-m', project.developmentVersion )
}
}

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

doFirst {
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
throw new GradleException(
"Task 'releasePrepare' requires all of the following properties to be set:"
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
)
}
}
}

def pushChangesTask = tasks.register( "pushChanges" ) {
description "Push the changes after preparing the release"
dependsOn releasePrepareTask

doFirst {
Expand All @@ -192,24 +238,21 @@ def ciReleaseTask = tasks.register( 'ciRelease' ) {
if ( tag.endsWith( ".Final" ) ) {
tag = tag.replace( ".Final", "" )
}
logger.lifecycle( "Tagging '${tag}'..." )
executeGitCommand( 'tag', '-a', '-m', "Release ${project.releaseVersion}", tag )

logger.lifecycle( "Adding commit to update version to '${project.developmentVersion}'..." )
project.projectVersionFile.text = "projectVersion=${project.developmentVersion}"
executeGitCommand( 'add', '.' )
executeGitCommand( 'commit', '-m', project.developmentVersion )

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

logger.lifecycle( "Done!" )

// logger
// .lifecycle( "Go to https://github.com/hibernate/hibernate-reactive/actions?query=branch%3A${tag} to check the progress of the automated release." )
}
}

/*
* Release everything
*/
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."
group "Release"
dependsOn pushChangesTask
}

static String executeGitCommand(Object ... subcommand){
List<Object> command = ['git']
Collections.addAll( command, subcommand )
Expand Down

0 comments on commit 6c14f64

Please sign in to comment.