@@ -209,6 +209,58 @@ tasks.named( "uploadDocumentation" ) {
209
209
def releaseChecksTask = tasks. register( " releaseChecks" ) {
210
210
group ' Release'
211
211
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
+ }
212
264
}
213
265
214
266
def preVerifyReleaseTask = tasks. register( " preVerifyRelease" ){
@@ -243,6 +295,7 @@ def changeToReleaseVersionTask = tasks.register( "changeToReleaseVersion" ) {
243
295
}
244
296
245
297
def gitPreparationForReleaseTask = tasks. register( ' gitPreparationForRelease' ) {
298
+ dependsOn releaseChecksTask
246
299
dependsOn changeLogFileTask
247
300
dependsOn changeToReleaseVersionTask
248
301
@@ -286,7 +339,6 @@ void updateVersionFile(String version) {
286
339
}
287
340
288
341
def publishReleaseArtifactsTask = tasks. register( ' publishReleaseArtifacts' ) {
289
- dependsOn releaseChecksTask
290
342
mustRunAfter gitPreparationForReleaseTask
291
343
292
344
dependsOn uploadDocumentation
@@ -304,7 +356,7 @@ def releaseTask = tasks.register( 'release' ) {
304
356
}
305
357
306
358
def ciReleaseChecksTask = tasks. register( ' ciReleaseChecks' ) {
307
- dependsOn releaseChecks
359
+
308
360
}
309
361
310
362
def gitTasksAfterCiReleaseTask = tasks. register( ' gitTasksAfterCiRelease' ) {
@@ -503,58 +555,6 @@ gradle.getTaskGraph().whenReady {tg->
503
555
createTag = ! project. hasProperty(' noTag' )
504
556
releaseTag = project. createTag ? determineReleaseTag(releaseVersionLocal) : ' '
505
557
}
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
- }
558
558
}
559
559
}
560
560
0 commit comments