Skip to content

Commit 6c14f64

Browse files
committed
fix
1 parent dee7b6e commit 6c14f64

File tree

1 file changed

+70
-27
lines changed

1 file changed

+70
-27
lines changed

release/build.gradle

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,14 @@ def publishDocumentationTask = tasks.register( 'publishDocumentation' ) {
125125
}
126126
}
127127

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

133131
doFirst {
134132
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
135133
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
136134
throw new GradleException(
137-
"Task 'releasePrepare' requires all of the following properties to be set:"
135+
"Task 'createTag' requires all of the following properties to be set:"
138136
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
139137
)
140138
}
@@ -147,25 +145,73 @@ def releasePrepareTask = tasks.register( "releasePrepare" ) {
147145
logger.lifecycle( "Checking that all commits are pushed..." )
148146
String diffWithUpstream = executeGitCommand( 'diff', '@{u}' )
149147
if ( !diffWithUpstream.isEmpty() ) {
150-
throw new GradleException(
151-
"Cannot release because there are commits on the branch to release that haven't been pushed yet."
152-
+ "\nPush your commits to the branch to release first."
153-
)
148+
throw new GradleException( "There are commits on the branch to release that haven't been pushed yet" )
154149
}
155150

156-
logger.lifecycle( "Adding commit to update version to '${project.releaseVersion}'..." )
151+
logger.lifecycle( "Commit version update to '${project.releaseVersion}'..." )
157152
project.projectVersionFile.text = "projectVersion=${project.releaseVersion}"
158153
executeGitCommand( 'add', '.' )
159154
executeGitCommand( 'commit', '-m', project.releaseVersion )
155+
156+
String tag = project.releaseVersion
157+
if ( tag.endsWith( ".Final" ) ) {
158+
tag = tag.replace( ".Final", "" )
159+
}
160+
logger.lifecycle( "Tagging '${tag}'..." )
161+
executeGitCommand( 'tag', '-a', '-m', "Release ${project.releaseVersion}", tag )
160162
}
161163
}
162164

163-
/*
164-
* Release everything
165-
*/
166-
def ciReleaseTask = tasks.register( 'ciRelease' ) {
167-
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."
165+
def updateVersionsTask = tasks.register( "updateVersions" ) {
166+
description "Update the release and development version, commit the changes, and create the tag"
168167
group "Release"
168+
dependsOn createTagTask
169+
170+
doFirst {
171+
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
172+
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
173+
throw new GradleException(
174+
"Task 'releasePrepare' requires all of the following properties to be set:"
175+
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
176+
)
177+
}
178+
}
179+
180+
doLast {
181+
logger.lifecycle( "Checking that the working tree is clean..." )
182+
String uncommittedFiles = executeGitCommand( 'status', '--porcelain' )
183+
if ( !uncommittedFiles.isEmpty() ) {
184+
throw new GradleException(
185+
"Cannot update the version because there are uncommitted changes in the working tree."
186+
+ "\nUncommitted files:\n" + uncommittedFiles
187+
)
188+
}
189+
190+
logger.lifecycle( "Adding commit to update version to '${project.developmentVersion}'..." )
191+
project.projectVersionFile.text = "projectVersion=${project.developmentVersion}"
192+
executeGitCommand( 'add', '.' )
193+
executeGitCommand( 'commit', '-m', project.developmentVersion )
194+
}
195+
}
196+
197+
def releasePrepareTask = tasks.register( "releasePrepare" ) {
198+
description "On a local checkout, performs all the changes required for the release"
199+
group "Release"
200+
dependsOn updateVersionsTask
201+
202+
doFirst {
203+
if ( !project.hasProperty( 'releaseVersion' ) || !project.hasProperty( 'developmentVersion' )
204+
|| !project.hasProperty( 'gitRemote' ) || !project.hasProperty( 'gitBranch' ) ) {
205+
throw new GradleException(
206+
"Task 'releasePrepare' requires all of the following properties to be set:"
207+
+ "'releaseVersion', 'developmentVersion', 'gitRemote' and 'gitBranch'."
208+
)
209+
}
210+
}
211+
}
212+
213+
def pushChangesTask = tasks.register( "pushChanges" ) {
214+
description "Push the changes after preparing the release"
169215
dependsOn releasePrepareTask
170216

171217
doFirst {
@@ -192,24 +238,21 @@ def ciReleaseTask = tasks.register( 'ciRelease' ) {
192238
if ( tag.endsWith( ".Final" ) ) {
193239
tag = tag.replace( ".Final", "" )
194240
}
195-
logger.lifecycle( "Tagging '${tag}'..." )
196-
executeGitCommand( 'tag', '-a', '-m', "Release ${project.releaseVersion}", tag )
197-
198-
logger.lifecycle( "Adding commit to update version to '${project.developmentVersion}'..." )
199-
project.projectVersionFile.text = "projectVersion=${project.developmentVersion}"
200-
executeGitCommand( 'add', '.' )
201-
executeGitCommand( 'commit', '-m', project.developmentVersion )
202-
203241
logger.lifecycle( "Pushing branch and tag to remote '${project.gitRemote}'..." )
204242
executeGitCommand( 'push', '--atomic', project.gitRemote, project.gitBranch, tag )
205-
206243
logger.lifecycle( "Done!" )
207-
208-
// logger
209-
// .lifecycle( "Go to https://github.com/hibernate/hibernate-reactive/actions?query=branch%3A${tag} to check the progress of the automated release." )
210244
}
211245
}
212246

247+
/*
248+
* Release everything
249+
*/
250+
def ciReleaseTask = tasks.register( 'ciRelease' ) {
251+
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."
252+
group "Release"
253+
dependsOn pushChangesTask
254+
}
255+
213256
static String executeGitCommand(Object ... subcommand){
214257
List<Object> command = ['git']
215258
Collections.addAll( command, subcommand )

0 commit comments

Comments
 (0)