Add more precondition checks to release tasks
This commit is contained in:
parent
70721d80a7
commit
02abce69fa
|
@ -13,11 +13,52 @@ apply from: rootProject.file( 'gradle/base-information.gradle' )
|
|||
apply plugin: 'idea'
|
||||
apply plugin: 'distribution'
|
||||
|
||||
ext {
|
||||
if ( !project.hasProperty( 'gitRemote' ) ) {
|
||||
gitRemote = 'origin'
|
||||
}
|
||||
}
|
||||
|
||||
idea.module {
|
||||
}
|
||||
|
||||
final File documentationDir = mkdir( "${project.buildDir}/documentation" );
|
||||
|
||||
task releaseChecks() {
|
||||
doFirst {
|
||||
if ( !project.hasProperty('releaseVersion') || !project.hasProperty('developmentVersion')
|
||||
|| !project.hasProperty('gitRemote') ||!project.hasProperty('gitBranch') ) {
|
||||
throw new GradleException(
|
||||
"Release tasks require all of the following properties to be set:"
|
||||
+ "'releaseVersion', 'developmentVersion', 'gitRemote', 'gitBranch'."
|
||||
)
|
||||
}
|
||||
|
||||
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."
|
||||
+ "\nCommit or stash your changes first."
|
||||
+ "\nUncommitted files:\n" + uncommittedFiles
|
||||
);
|
||||
}
|
||||
|
||||
logger.lifecycle( "Switching to branch '${project.gitBranch}'..." )
|
||||
executeGitCommand( 'switch', project.gitBranch )
|
||||
|
||||
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."
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles all documentation into the {buildDir}/documentation directory.
|
||||
*
|
||||
|
@ -246,23 +287,12 @@ artifacts {
|
|||
bundles distZip
|
||||
}
|
||||
|
||||
task release( dependsOn: [uploadDocumentation, uploadBundlesSourceForge] )
|
||||
task release( dependsOn: [releaseChecks, uploadDocumentation, uploadBundlesSourceForge] )
|
||||
|
||||
def gitRemote = 'origin'
|
||||
if ( project.hasProperty( 'gitRemote' ) ) {
|
||||
gitRemote = project.property( 'gitRemote' )
|
||||
}
|
||||
|
||||
task addVersionCommit {
|
||||
task addVersionCommit( dependsOn: [releaseChecks] ) {
|
||||
group = "Release"
|
||||
description = "Updates the changelog.txt file, adds a commit for the released version and push the changes to github"
|
||||
doFirst{
|
||||
if ( !project.hasProperty( 'releaseVersion' ) ) {
|
||||
throw new GradleException(
|
||||
"The releaseVersion parameter is necessary to create the version commit."
|
||||
)
|
||||
}
|
||||
|
||||
logger.lifecycle( "Updating version to '${project.releaseVersion}'..." )
|
||||
project.ormVersionFile.text = "hibernateVersion=${project.releaseVersion}"
|
||||
|
||||
|
@ -272,19 +302,15 @@ task addVersionCommit {
|
|||
logger.lifecycle( "Adding commit to update version to '${project.releaseVersion}'..." )
|
||||
executeGitCommand( 'add', '.' )
|
||||
executeGitCommand( 'commit', '-m', project.ormVersion.fullName )
|
||||
executeGitCommand( 'push', gitRemote )
|
||||
executeGitCommand( 'push', project.gitRemote )
|
||||
}
|
||||
}
|
||||
release.mustRunAfter addVersionCommit
|
||||
|
||||
task ciRelease() {
|
||||
task ciRelease( dependsOn: [releaseChecks, addVersionCommit, release] ) {
|
||||
group = "Release"
|
||||
description = "Performs a release: the hibernate version is set and the changelog.txt file updated, the changes are pushed to github, then the release is performed, tagged and the hibernate version is set to the development one."
|
||||
doLast {
|
||||
if ( !project.hasProperty( 'developmentVersion' ) ) {
|
||||
throw new GradleException(
|
||||
"When the releaseVersion parameter is specified, the parameter developmentVersion is required as well."
|
||||
)
|
||||
}
|
||||
if ( !project.hasProperty( 'noTag' ) ) {
|
||||
String tag = project.ormVersion.fullName
|
||||
// the release is tagged and the tag is pushed to github
|
||||
|
@ -293,21 +319,18 @@ task ciRelease() {
|
|||
}
|
||||
logger.lifecycle( "Tagging '${tag}'..." )
|
||||
executeGitCommand( 'tag', tag )
|
||||
executeGitCommand( 'push', gitRemote, tag )
|
||||
executeGitCommand( 'push', project.gitRemote, tag )
|
||||
|
||||
logger.lifecycle( "Adding commit to update version to '${project.developmentVersion}'..." )
|
||||
project.ormVersionFile.text = "hibernateVersion=${project.developmentVersion}"
|
||||
executeGitCommand( 'add', '.')
|
||||
executeGitCommand( 'commit', '-m', project.developmentVersion )
|
||||
executeGitCommand( 'push', gitRemote )
|
||||
executeGitCommand( 'push', project.gitRemote )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ciRelease.dependsOn addVersionCommit, release
|
||||
release.mustRunAfter addVersionCommit
|
||||
|
||||
static void executeGitCommand(Object ... subcommand){
|
||||
static String executeGitCommand(Object ... subcommand){
|
||||
List<Object> command = ['git']
|
||||
Collections.addAll( command, subcommand )
|
||||
def proc = command.execute()
|
||||
|
@ -317,6 +340,7 @@ static void executeGitCommand(Object ... subcommand){
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue