view scripts/release.groovy @ 215:5bebb590b30e

DEP-11: determine project version based on branch
author smith@nwoca.org
date Tue, 28 Jun 2016 23:01:21 +0100
parents f200b931ea9d
children b628d49d2891
line wrap: on
line source
#!groovy

/**
This script implements the SSDT branching strategy based on hg flow.  

The intention is to reduce drudgery of creating 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.

*/
	def project = new Properties()

	if (new File('gradle.properties').exists() ) {
		project.load(new File('gradle.properties').newInputStream())
	}	
	
	println "\nCurrent project:"
	println "\tversion: " + project.version ?: "Unknown"
	println "-" * 20
	
if (args.size() < 2) {
	println """	
	usage:  release.groovy {releaseVersion} {nextVersion}\n
	  e.g:  release.groovy 1.6.0 1.7.0    (SNAPSHOT will be added automatically)
	  
	If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'.
	For hotfix, current working branch should be the release branch.
	
	Recommend that this script be executed in a fresh clone of the repo.
	
	** Any uncommitted changes in the working directory will be committed with
	   the initial setting of the version. These are assumed to be
	   'latest.integration' changes.
"""	

	System.exit(0)
}

def releaseVersion = args[0]
def nextVersion = args[1]
def hotfix = !releaseVersion.endsWith('.0')
def stream = hotfix ? 'hotfix' : 'release'

println "Creating ${hotfix ? 'hotfix' : 'release'} branch for $releaseVersion"

checkForSnapshots()

println "hg flow $stream start v${releaseVersion} --dry-run".execute().text

println "Continue? Enter = Yes, ^C to cancel"
System.in.newReader().readLine()

updateVersion(releaseVersion)

println 'hg com -m "release: set release version"'.execute().text

println "hg flow ${stream} start v${releaseVersion} --dirty".execute().text

println "hg update default".execute().text

updateVersion(nextVersion + ".SNAPSHOT")

println 'hg com -m "release: set next release version"'.execute().text

println "hg update ${stream}/v${releaseVersion}".execute().text

println "Done! Created $releaseVersion $stream branch."
println "      Verify the branch created correctly then push the new branch."
println "      If any problems, then delete repo and clone fresh repository."

def updateVersion(String newVersion) {

	new File('gradle.properties').write(
		new File('gradle.properties').text.replaceAll(/version=(.*)/,"version=$newVersion")
	)
}

def checkForSnapshots() {
		def lines = new File('gradle.properties').readLines() + new File('build.gradle').readLines()
		def snapshots = lines.collect { it.trim() }.findAll{ 
			it.contains('.SNAPSHOT') && !it.startsWith('version=') ||
			it.contains('latest.') && (it.startsWith('compile') || it.startsWith('runtime'))
		}
		if (snapshots) {
			println "project contains SNAPSHOT dependencies: \n\t" + snapshots.join('\n\t')
			System.exit(1)
		}

}