comparison scripts/release.groovy @ 208:f200b931ea9d

add release and hgflow scripts
author smith@nwoca.org
date Sat, 19 Dec 2015 14:26:46 +0000
parents
children 5bebb590b30e
comparison
equal deleted inserted replaced
207:7a17678c9a73 208:f200b931ea9d
1 #!groovy
2
3 /**
4 This script implements the SSDT branching strategy based on hg flow.
5
6 The intension is to reduce dudgery of creating release branches. The
7 script tries to do the right thing based on standard SSDT project structures,
8 but it is the user's responsibility to ensure it's correct.
9
10 The script does NOT "hg push --new-branch". That step is left for you
11 if the branch was created correctly.
12
13 */
14 def project = new Properties()
15
16 if (new File('gradle.properties').exists() ) {
17 project.load(new File('gradle.properties').newInputStream())
18 }
19
20 println "\nCurrent project:"
21 println "\tversion: " + project.version ?: "Unknown"
22 println "-" * 20
23
24 if (args.size() < 2) {
25 println """
26 usage: release.groovy {releaseVersion} {nextVersion}\n
27 e.g: release.groovy 1.6.0 1.7.0 (SNAPSHOT will be added automatically)
28
29 If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'.
30 For hotfix, current working branch should be the release branch.
31
32 Recommend that this script be executed in a fresh clone of the repo.
33
34 ** Any uncommitted changes in the working directory will be committed with
35 the initial setting of the version. This are assumed to be
36 'latest.integration' changes.
37 """
38
39 System.exit(0)
40 }
41
42 def releaseVersion = args[0]
43 def nextVersion = args[1]
44 def hotfix = !releaseVersion.endsWith('.0')
45 def stream = hotfix ? 'hotfix' : 'release'
46
47 println "Creating ${hotfix ? 'hotfix' : 'release'} branch for $releaseVersion"
48
49 checkForSnapshots()
50
51 println "hg flow $stream start v${releaseVersion} --dry-run".execute().text
52
53 println "Continue? Enter = Yes, ^C to cancel"
54 System.in.newReader().readLine()
55
56 updateVersion(releaseVersion)
57
58 println 'hg com -m "release: set release version"'.execute().text
59
60 println "hg flow ${stream} start v${releaseVersion} --dirty".execute().text
61
62 println "hg update default".execute().text
63
64 updateVersion(nextVersion + ".SNAPSHOT")
65
66 println 'hg com -m "release: set next release version"'.execute().text
67
68 println "hg update ${stream}/v${releaseVersion}".execute().text
69
70 println "Done! Created $releaseVersion $stream branch."
71 println " Verify the branch created correctly then push the new branch."
72 println " If any problems, then delete repo and clone fresh repository."
73
74 def updateVersion(String newVersion) {
75
76 new File('gradle.properties').write(
77 new File('gradle.properties').text.replaceAll(/version=(.*)/,"version=$newVersion")
78 )
79 }
80
81 def checkForSnapshots() {
82 def lines = new File('gradle.properties').readLines() + new File('build.gradle').readLines()
83 def snapshots = lines.collect { it.trim() }.findAll{
84 it.contains('.SNAPSHOT') && !it.startsWith('version=') ||
85 it.contains('latest.') && (it.startsWith('compile') || it.startsWith('runtime'))
86 }
87 if (snapshots) {
88 println "project contains SNAPSHOT dependencies: \n\t" + snapshots.join('\n\t')
89 System.exit(1)
90 }
91
92 }
93