diff scripts/release.groovy @ 217:49a220a1bde0

DEP-11: allow keywords to calculate release version based on current branch
author smith@nwoca.org
date Wed, 29 Jun 2016 19:47:31 +0100
parents b628d49d2891
children
line wrap: on
line diff
--- a/scripts/release.groovy	Wed Jun 29 13:57:17 2016 +0100
+++ b/scripts/release.groovy	Wed Jun 29 19:47:31 2016 +0100
@@ -4,15 +4,15 @@
 import groovy.transform.TupleConstructor
 
 /**
-This script implements the SSDT branching strategy based on hg flow
+ This script implements the SSDT branching strategy based on hg flow
  and dependency resolution locking.
 
-The intention is to automate of creation of correctly configured release branches.
+ The intention is to automate of creation of correctly configured release branches.
  The script tries to do the right thing based on standard SSDT project structures,
  but it is the user's responsibility to ensure it's correct.
 
-The script does NOT "hg push --new-branch".   That step is left for you
-if the branch was created correctly.
+ The script does NOT "hg push --new-branch".   That step is left for you
+ if the branch was created correctly.
 
 */
 
@@ -29,9 +29,12 @@
 
 if (args.size() < 1) {
 	println """	
-	usage:  release.groovy {releaseVersion}\n
-	  e.g:  release.groovy 1.6.0
-	  
+	usage:  release.groovy {major|minor|patch|n.n.n}\n
+	  e.g:  release.groovy minor
+
+	If "major", "minor" or "patch" is specified, then the release version is
+	calculated based on the current branch.  Otherwise specify a specific version.
+
 	If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'.
 	For hotfix, current working branch should be the release branch being hotfix'ed.
 	
@@ -45,12 +48,24 @@
 	System.exit(0)
 }
 
-def releaseVersion = args[0]
+def releaseVersion
 
-def hotfix = !releaseVersion.endsWith('.0')
+if ( args[0] == 'major') {
+	releaseVersion = branch.version.nextMajor()
+} else if ( args[0] == 'minor') {
+	releaseVersion = branch.version.nextMinor()
+} else if ( args[0] == 'patch') {
+	releaseVersion = branch.version.nextPatch()
+} else {
+	releaseVersion = new Version(*args[0].split('\\.')*.toInteger())
+}
+
+def hotfix = releaseVersion.patch > 0
+
 def stream = hotfix ? 'hotfix' : 'release'
 
-println "Creating $stream branch for $releaseVersion"
+println "Preparing to create $stream branch for version $releaseVersion"
+println()
 
 checkForSnapshots()
 
@@ -64,7 +79,7 @@
 println "hg update ${stream}/v${releaseVersion}".execute().text
 
 println "Starting dependency lock via gradle... (please wait)"
-println "cmd /c gradlew.bat deleteGLobalLock generateGlobalLock saveGlobalLock".execute().text
+println "cmd /c gradlew.bat deleteGlobalLock generateGlobalLock saveGlobalLock".execute().text
 
 println 'hg commit -A release.lock -m "lock dynamic dependencies for release"'.execute().text
 
@@ -92,10 +107,26 @@
 	Integer major = 0
 	Integer minor = 0
 	Integer patch = 0
-	Boolean snapshot = true
+	Boolean snapshot = false
+
+	Version nextMajor() {
+		new Version(major + 1, 0, 0)
+	}
 
-	Version nextVersion() {
-		new Version(major, minor + 1, 0)
+	Version nextMinor() {
+		if (snapshot) {
+			new Version(major, minor , 0)
+		} else {
+			new Version(major, minor + 1, 0)
+		}
+	}
+
+	Version nextSnapshot() {
+		new Version(major, minor + 1, 0,true)
+	}
+
+	Version nextPatch() {
+		new Version(major, minor, patch + 1)
 	}
 
 	String toString() {
@@ -165,6 +196,7 @@
 	def getHash() {
 		generateMD5(name)
 	}
+
 	def generateMD5(String s) {
 		def digest = java.security.MessageDigest.getInstance("MD5")
 		digest.update(s.bytes);
@@ -177,10 +209,10 @@
 		}.collect {
 			it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v'
 		}.collect {
-			new Version(*it.split('\\.')*.toInteger())
+			new Version(*it.split('\\.')*.toInteger(),true)
 		}.sort { v1, v2 -> v2 <=> v1 }
 
-		return versions ?  versions.first().nextVersion() : new Version().nextVersion()
+		return versions ?  versions.first().nextSnapshot() : new Version().nextSnapshot()
 
 	}