Mercurial > public > develkit
comparison 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 |
comparison
equal
deleted
inserted
replaced
216:b628d49d2891 | 217:49a220a1bde0 |
---|---|
2 import groovy.transform.Sortable | 2 import groovy.transform.Sortable |
3 import groovy.transform.ToString | 3 import groovy.transform.ToString |
4 import groovy.transform.TupleConstructor | 4 import groovy.transform.TupleConstructor |
5 | 5 |
6 /** | 6 /** |
7 This script implements the SSDT branching strategy based on hg flow | 7 This script implements the SSDT branching strategy based on hg flow |
8 and dependency resolution locking. | 8 and dependency resolution locking. |
9 | 9 |
10 The intention is to automate of creation of correctly configured release branches. | 10 The intention is to automate of creation of correctly configured release branches. |
11 The script tries to do the right thing based on standard SSDT project structures, | 11 The script tries to do the right thing based on standard SSDT project structures, |
12 but it is the user's responsibility to ensure it's correct. | 12 but it is the user's responsibility to ensure it's correct. |
13 | 13 |
14 The script does NOT "hg push --new-branch". That step is left for you | 14 The script does NOT "hg push --new-branch". That step is left for you |
15 if the branch was created correctly. | 15 if the branch was created correctly. |
16 | 16 |
17 */ | 17 */ |
18 | 18 |
19 def branch = new BranchInfo() | 19 def branch = new BranchInfo() |
20 | 20 |
27 println "-" * 40 | 27 println "-" * 40 |
28 println "" | 28 println "" |
29 | 29 |
30 if (args.size() < 1) { | 30 if (args.size() < 1) { |
31 println """ | 31 println """ |
32 usage: release.groovy {releaseVersion}\n | 32 usage: release.groovy {major|minor|patch|n.n.n}\n |
33 e.g: release.groovy 1.6.0 | 33 e.g: release.groovy minor |
34 | 34 |
35 If "major", "minor" or "patch" is specified, then the release version is | |
36 calculated based on the current branch. Otherwise specify a specific version. | |
37 | |
35 If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'. | 38 If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'. |
36 For hotfix, current working branch should be the release branch being hotfix'ed. | 39 For hotfix, current working branch should be the release branch being hotfix'ed. |
37 | 40 |
38 Recommend that this script be executed in a fresh clone of the repo. | 41 Recommend that this script be executed in a fresh clone of the repo. |
39 | 42 |
43 """ | 46 """ |
44 | 47 |
45 System.exit(0) | 48 System.exit(0) |
46 } | 49 } |
47 | 50 |
48 def releaseVersion = args[0] | 51 def releaseVersion |
49 | 52 |
50 def hotfix = !releaseVersion.endsWith('.0') | 53 if ( args[0] == 'major') { |
54 releaseVersion = branch.version.nextMajor() | |
55 } else if ( args[0] == 'minor') { | |
56 releaseVersion = branch.version.nextMinor() | |
57 } else if ( args[0] == 'patch') { | |
58 releaseVersion = branch.version.nextPatch() | |
59 } else { | |
60 releaseVersion = new Version(*args[0].split('\\.')*.toInteger()) | |
61 } | |
62 | |
63 def hotfix = releaseVersion.patch > 0 | |
64 | |
51 def stream = hotfix ? 'hotfix' : 'release' | 65 def stream = hotfix ? 'hotfix' : 'release' |
52 | 66 |
53 println "Creating $stream branch for $releaseVersion" | 67 println "Preparing to create $stream branch for version $releaseVersion" |
68 println() | |
54 | 69 |
55 checkForSnapshots() | 70 checkForSnapshots() |
56 | 71 |
57 println "hg flow $stream start v${releaseVersion} --dry-run".execute().text | 72 println "hg flow $stream start v${releaseVersion} --dry-run".execute().text |
58 | 73 |
62 println "hg flow ${stream} start v${releaseVersion} --dirty".execute().text | 77 println "hg flow ${stream} start v${releaseVersion} --dirty".execute().text |
63 | 78 |
64 println "hg update ${stream}/v${releaseVersion}".execute().text | 79 println "hg update ${stream}/v${releaseVersion}".execute().text |
65 | 80 |
66 println "Starting dependency lock via gradle... (please wait)" | 81 println "Starting dependency lock via gradle... (please wait)" |
67 println "cmd /c gradlew.bat deleteGLobalLock generateGlobalLock saveGlobalLock".execute().text | 82 println "cmd /c gradlew.bat deleteGlobalLock generateGlobalLock saveGlobalLock".execute().text |
68 | 83 |
69 println 'hg commit -A release.lock -m "lock dynamic dependencies for release"'.execute().text | 84 println 'hg commit -A release.lock -m "lock dynamic dependencies for release"'.execute().text |
70 | 85 |
71 println "Created $releaseVersion $stream branch with locked dynamic dependencies." | 86 println "Created $releaseVersion $stream branch with locked dynamic dependencies." |
72 println " Verify the branch and release.lock file created correctly then push the new branch." | 87 println " Verify the branch and release.lock file created correctly then push the new branch." |
90 class Version { | 105 class Version { |
91 | 106 |
92 Integer major = 0 | 107 Integer major = 0 |
93 Integer minor = 0 | 108 Integer minor = 0 |
94 Integer patch = 0 | 109 Integer patch = 0 |
95 Boolean snapshot = true | 110 Boolean snapshot = false |
96 | 111 |
97 Version nextVersion() { | 112 Version nextMajor() { |
98 new Version(major, minor + 1, 0) | 113 new Version(major + 1, 0, 0) |
114 } | |
115 | |
116 Version nextMinor() { | |
117 if (snapshot) { | |
118 new Version(major, minor , 0) | |
119 } else { | |
120 new Version(major, minor + 1, 0) | |
121 } | |
122 } | |
123 | |
124 Version nextSnapshot() { | |
125 new Version(major, minor + 1, 0,true) | |
126 } | |
127 | |
128 Version nextPatch() { | |
129 new Version(major, minor, patch + 1) | |
99 } | 130 } |
100 | 131 |
101 String toString() { | 132 String toString() { |
102 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}" | 133 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}" |
103 } | 134 } |
163 } | 194 } |
164 | 195 |
165 def getHash() { | 196 def getHash() { |
166 generateMD5(name) | 197 generateMD5(name) |
167 } | 198 } |
199 | |
168 def generateMD5(String s) { | 200 def generateMD5(String s) { |
169 def digest = java.security.MessageDigest.getInstance("MD5") | 201 def digest = java.security.MessageDigest.getInstance("MD5") |
170 digest.update(s.bytes); | 202 digest.update(s.bytes); |
171 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') | 203 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0') |
172 } | 204 } |
175 def versions = "hg branches --closed".execute().text.split('\n').findAll { | 207 def versions = "hg branches --closed".execute().text.split('\n').findAll { |
176 it.startsWith( 'release') || it.startsWith( 'hotfix') | 208 it.startsWith( 'release') || it.startsWith( 'hotfix') |
177 }.collect { | 209 }.collect { |
178 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' | 210 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v' |
179 }.collect { | 211 }.collect { |
180 new Version(*it.split('\\.')*.toInteger()) | 212 new Version(*it.split('\\.')*.toInteger(),true) |
181 }.sort { v1, v2 -> v2 <=> v1 } | 213 }.sort { v1, v2 -> v2 <=> v1 } |
182 | 214 |
183 return versions ? versions.first().nextVersion() : new Version().nextVersion() | 215 return versions ? versions.first().nextSnapshot() : new Version().nextSnapshot() |
184 | 216 |
185 } | 217 } |
186 | 218 |
187 | 219 |
188 def determineName() { | 220 def determineName() { |