Mercurial > public > develkit
comparison init20.gradle @ 219:efa545c6dd65
DEP-11: implement release process as gradle rule
author | smith@nwoca.org |
---|---|
date | Fri, 01 Jul 2016 20:56:04 +0100 |
parents | b628d49d2891 |
children | 837c9249053f |
comparison
equal
deleted
inserted
replaced
218:92dd8c69b98c | 219:efa545c6dd65 |
---|---|
339 | 339 |
340 } | 340 } |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 } | 344 tasks.addRule("release{Major|Minor|Patch|n.n.n}: create release branch") { String taskName -> |
345 | 345 |
346 def matcher = (taskName =~ /^release(Major|Minor|Patch|\d{1,3}\.\d{1,3}\.\d{1,3})$/) | |
347 if (matcher.matches()) { | |
348 | |
349 | |
350 dependencyLock.globalLockFile = 'release.lock' | |
351 | |
352 | |
353 task('doReleaseBranch') { | |
354 ext.requested = matcher[0][1].toLowerCase() | |
355 } << { | |
356 def releaseVersion = determineReleaseVersion(requested) | |
357 def releaseStream = releaseVersion.isHotfix() ? 'hotfix' : 'release' | |
358 | |
359 println "-" * 60 | |
360 println "Preparing to create branch\n" | |
361 println "\tproject:\t${gradle.rootProject.name}" | |
362 println "\tcurrent:\t${gradle.branch} ($gradle.branch.version)" | |
363 println() | |
364 println "\ttype :\t${releaseStream.toUpperCase()}" | |
365 println "\tversion:\t${releaseVersion}" | |
366 println "\ttarget :\t${releaseStream}/v${releaseVersion}" | |
367 println() | |
368 println("-" * 60) | |
369 println "DRY RUN".center(60) | |
370 println("-" * 60) | |
371 | |
372 println "hg flow ${releaseStream} start v${releaseVersion} --dirty --dry-run".execute().text | |
373 | |
374 println "-" * 60 | |
375 | |
376 if (!confirmPrompt("Continue?")) { | |
377 throw new BuildCancelledException("release branching canceled by user request") | |
378 } | |
379 | |
380 println "hg flow ${releaseStream} start v${releaseVersion} --dirty".execute().text | |
381 println "hg update ${releaseStream}/v${releaseVersion}".execute().text | |
382 | |
383 } | |
384 | |
385 task('doCommitLock') << { | |
386 println 'hg status'.execute().text | |
387 println 'hg commit release.lock -A -m "lock dynamic dependencies for release"'.execute().text | |
388 } | |
389 | |
390 def branchTasks = ['doReleaseBranch', 'deleteGlobalLock', 'generateGlobalLock', 'saveGlobalLock', 'doCommitLock'] | |
391 | |
392 task(taskName) { | |
393 dependsOn branchTasks | |
394 } | |
395 | |
396 branchTasks.tail().inject(branchTasks.head()) { a, b -> | |
397 tasks[b].mustRunAfter a | |
398 b | |
399 } | |
400 | |
401 } | |
402 } | |
403 | |
404 } | |
405 | |
406 private static String readLine(String message, String defaultValue = null) { | |
407 String _message = "> $message" + (defaultValue ? " [$defaultValue] " : "") | |
408 if (System.console()) { | |
409 return System.console().readLine(_message) ?: defaultValue | |
410 } | |
411 println "$_message " | |
412 | |
413 System.in.newReader().readLine() ?: defaultValue | |
414 } | |
415 | |
416 private static boolean confirmPrompt(String message, boolean defaultValue = false) { | |
417 String defaultStr = defaultValue ? 'Y' : 'n' | |
418 String consoleVal = readLine("${message} (Y|n)", defaultStr) | |
419 if (consoleVal) { | |
420 return consoleVal.toLowerCase().startsWith('y') | |
421 } | |
422 | |
423 defaultValue | |
424 } | |
425 | |
426 private Version determineReleaseVersion(String requested) { | |
427 if (requested == 'major') { | |
428 return gradle.branch.version.nextMajor() | |
429 } else if (requested == 'minor') { | |
430 return gradle.branch.version.nextMinor() | |
431 } else if (requested == 'patch') { | |
432 return gradle.branch.version.nextPatch() | |
433 } else { | |
434 return new Version(*requested.split(/\./)*.toInteger(), false) | |
435 } | |
436 } | |
346 | 437 |
347 class ArtifactoryGradleSettings extends BuildAdapter implements BuildListener { | 438 class ArtifactoryGradleSettings extends BuildAdapter implements BuildListener { |
348 | 439 |
349 def void projectsEvaluated(Gradle gradle) { | 440 def void projectsEvaluated(Gradle gradle) { |
350 def ssdtArtifactory = 'http://repos.ssdt.nwoca.org/artifactory' | 441 def ssdtArtifactory = 'http://repos.ssdt.nwoca.org/artifactory' |
606 Integer major = 0 | 697 Integer major = 0 |
607 Integer minor = 0 | 698 Integer minor = 0 |
608 Integer patch = 0 | 699 Integer patch = 0 |
609 Boolean snapshot = true | 700 Boolean snapshot = true |
610 | 701 |
611 Version nextVersion() { | 702 Version nextMajor() { |
703 new Version(major + 1, 0, 0, false) | |
704 } | |
705 | |
706 Version nextMinor() { | |
707 if (snapshot) { | |
708 new Version(major, minor , 0,false) | |
709 } else { | |
710 new Version(major, minor + 1, 0,false) | |
711 } | |
712 } | |
713 | |
714 Version nextPatch() { | |
715 new Version(major, minor, patch + 1,false) | |
716 } | |
717 | |
718 Version nextSnapshot() { | |
612 new Version(major, minor + 1, 0) | 719 new Version(major, minor + 1, 0) |
720 } | |
721 | |
722 boolean isHotfix() { | |
723 !snapshot && patch > 0 | |
613 } | 724 } |
614 | 725 |
615 String toString() { | 726 String toString() { |
616 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}" | 727 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}" |
617 } | 728 } |
692 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' | 803 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' |
693 }.collect { | 804 }.collect { |
694 new Version(*it.split('\\.')*.toInteger()) | 805 new Version(*it.split('\\.')*.toInteger()) |
695 }.sort { v1, v2 -> v2 <=> v1 } | 806 }.sort { v1, v2 -> v2 <=> v1 } |
696 | 807 |
697 return versions ? versions.first().nextVersion() : new Version().nextVersion() | 808 return versions ? versions.first().nextSnapshot() : new Version().nextSnapshot() |
698 | 809 |
699 } | 810 } |
700 | 811 |
701 | 812 |
702 def determineName() { | 813 def determineName() { |