@@ -209,6 +209,58 @@ tasks.named( "uploadDocumentation" ) {
209209def releaseChecksTask = tasks. register( " releaseChecks" ) {
210210 group ' Release'
211211 description ' Checks and preparation for release'
212+
213+ doFirst {
214+ logger. lifecycle(" Checking that the working tree is clean..." )
215+ String uncommittedFiles = executeGitCommand(' status' , ' --porcelain' )
216+ if (! uncommittedFiles. isEmpty()) {
217+ throw new GradleException (
218+ " Cannot release because there are uncommitted or untracked files in the working tree.\n " +
219+ " Commit or stash your changes first.\n " +
220+ " Uncommitted files:\n " +
221+ uncommittedFiles
222+ );
223+ }
224+
225+ String gitBranchLocal
226+ String gitRemoteLocal
227+
228+ if (project. hasProperty(' gitBranch' )) {
229+ gitBranchLocal = project. property(' gitBranch' )
230+ }
231+ else {
232+ gitBranchLocal = executeGitCommand( ' branch' , ' --show-current' )
233+ }
234+
235+ if (project. hasProperty(' gitRemote' )) {
236+ gitRemoteLocal = project. property(' gitRemote' )
237+ }
238+ else {
239+ final String remotes = executeGitCommand( ' remote' , ' show' )
240+ final List<String > tokens = remotes. tokenize()
241+ if ( tokens. size() != 1 ) {
242+ throw new GradleException ( " Could not determine `gitRemote` property for `releaseChecks` tasks." )
243+ }
244+ gitRemoteLocal = tokens. get( 0 )
245+ }
246+
247+ project. ext {
248+ gitBranch = gitBranchLocal
249+ gitRemote = gitRemoteLocal
250+ }
251+
252+ logger. lifecycle(" Switching to branch '${ project.gitBranch} '..." )
253+ executeGitCommand(' checkout' , project. gitBranch)
254+
255+ logger. lifecycle(" Checking that all commits are pushed..." )
256+ String diffWithUpstream = executeGitCommand(' diff' , ' @{u}' )
257+ if (! diffWithUpstream. isEmpty()) {
258+ throw new GradleException (
259+ " Cannot perform `ciRelease` tasks because there are un-pushed local commits .\n " +
260+ " Push your commits first."
261+ );
262+ }
263+ }
212264}
213265
214266def preVerifyReleaseTask = tasks. register( " preVerifyRelease" ){
@@ -243,6 +295,7 @@ def changeToReleaseVersionTask = tasks.register( "changeToReleaseVersion" ) {
243295}
244296
245297def gitPreparationForReleaseTask = tasks. register( ' gitPreparationForRelease' ) {
298+ dependsOn releaseChecksTask
246299 dependsOn changeLogFileTask
247300 dependsOn changeToReleaseVersionTask
248301
@@ -286,7 +339,6 @@ void updateVersionFile(String version) {
286339}
287340
288341def publishReleaseArtifactsTask = tasks. register( ' publishReleaseArtifacts' ) {
289- dependsOn releaseChecksTask
290342 mustRunAfter gitPreparationForReleaseTask
291343
292344 dependsOn uploadDocumentation
@@ -304,7 +356,7 @@ def releaseTask = tasks.register( 'release' ) {
304356}
305357
306358def ciReleaseChecksTask = tasks. register( ' ciReleaseChecks' ) {
307- dependsOn releaseChecks
359+
308360}
309361
310362def gitTasksAfterCiReleaseTask = tasks. register( ' gitTasksAfterCiRelease' ) {
@@ -503,58 +555,6 @@ gradle.getTaskGraph().whenReady {tg->
503555 createTag = ! project. hasProperty(' noTag' )
504556 releaseTag = project. createTag ? determineReleaseTag(releaseVersionLocal) : ' '
505557 }
506-
507- logger. lifecycle(" Checking that the working tree is clean..." )
508- String uncommittedFiles = executeGitCommand(' status' , ' --porcelain' )
509- if (! uncommittedFiles. isEmpty()) {
510- throw new GradleException (
511- " Cannot release because there are uncommitted or untracked files in the working tree.\n " +
512- " Commit or stash your changes first.\n " +
513- " Uncommitted files:\n " +
514- uncommittedFiles
515- );
516- }
517-
518- if (tg. hasTask(project. tasks. ciReleaseChecks)) {
519- String gitBranchLocal
520- String gitRemoteLocal
521-
522- if (project. hasProperty(' gitBranch' )) {
523- gitBranchLocal = project. property(' gitBranch' )
524- }
525- else {
526- gitBranchLocal = executeGitCommand( ' branch' , ' --show-current' )
527- }
528-
529- if (project. hasProperty(' gitRemote' )) {
530- gitRemoteLocal = project. property(' gitRemote' )
531- }
532- else {
533- final String remotes = executeGitCommand( ' remote' , ' show' )
534- final List<String > tokens = remotes. tokenize()
535- if ( tokens. size() != 1 ) {
536- throw new GradleException ( " Could not determine `gitRemote` property for `ciRelease` tasks." )
537- }
538- gitRemoteLocal = tokens. get( 0 )
539- }
540-
541- project. ext {
542- gitBranch = gitBranchLocal
543- gitRemote = gitRemoteLocal
544- }
545-
546- logger. lifecycle(" Switching to branch '${ project.gitBranch} '..." )
547- executeGitCommand(' checkout' , project. gitBranch)
548-
549- logger. lifecycle(" Checking that all commits are pushed..." )
550- String diffWithUpstream = executeGitCommand(' diff' , ' @{u}' )
551- if (! diffWithUpstream. isEmpty()) {
552- throw new GradleException (
553- " Cannot perform `ciRelease` tasks because there are un-pushed local commits .\n " +
554- " Push your commits first."
555- );
556- }
557- }
558558 }
559559}
560560
0 commit comments