annotate 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
rev   line source
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
1 #!groovy
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
2 import groovy.transform.Sortable
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
3 import groovy.transform.ToString
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
4 import groovy.transform.TupleConstructor
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
5
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
6 /**
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
7 This script implements the SSDT branching strategy based on hg flow
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
8 and dependency resolution locking.
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
9
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
10 The intention is to automate of creation of correctly configured release branches.
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
11 The script tries to do the right thing based on standard SSDT project structures,
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
12 but it is the user's responsibility to ensure it's correct.
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
13
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
14 The script does NOT "hg push --new-branch". That step is left for you
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
15 if the branch was created correctly.
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
16
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
17 */
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
18
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
19 def branch = new BranchInfo()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
20
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
21 println "Project:\n"
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
22
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
23 println "\trepo\t${("hg path".execute().text.split('=') ?: ['', ''])[1].trim()}"
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
24 println "\tbranch\t$branch"
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
25 println "\tversion\t$branch.version"
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
26
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
27 println "-" * 40
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
28 println ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
29
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
30 if (args.size() < 1) {
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
31 println """
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
32 usage: release.groovy {major|minor|patch|n.n.n}\n
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
33 e.g: release.groovy minor
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
34
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
35 If "major", "minor" or "patch" is specified, then the release version is
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
36 calculated based on the current branch. Otherwise specify a specific version.
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
37
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
38 If release ends in ".0", then will create 'release' stream, otherwise 'hotfix'.
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
39 For hotfix, current working branch should be the release branch being hotfix'ed.
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
40
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
41 Recommend that this script be executed in a fresh clone of the repo.
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
42
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
43 ** Any uncommitted changes in the working directory will be committed with
215
5bebb590b30e DEP-11: determine project version based on branch
smith@nwoca.org
parents: 208
diff changeset
44 the initial setting of the version. These are assumed to be
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
45 'latest.integration' changes.
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
46 """
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
47
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
48 System.exit(0)
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
49 }
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
50
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
51 def releaseVersion
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
52
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
53 if ( args[0] == 'major') {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
54 releaseVersion = branch.version.nextMajor()
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
55 } else if ( args[0] == 'minor') {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
56 releaseVersion = branch.version.nextMinor()
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
57 } else if ( args[0] == 'patch') {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
58 releaseVersion = branch.version.nextPatch()
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
59 } else {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
60 releaseVersion = new Version(*args[0].split('\\.')*.toInteger())
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
61 }
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
62
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
63 def hotfix = releaseVersion.patch > 0
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
64
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
65 def stream = hotfix ? 'hotfix' : 'release'
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
66
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
67 println "Preparing to create $stream branch for version $releaseVersion"
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
68 println()
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
69
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
70 checkForSnapshots()
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
71
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
72 println "hg flow $stream start v${releaseVersion} --dry-run".execute().text
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
73
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
74 println "Continue? Enter = Yes, ^C to cancel"
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
75 System.in.newReader().readLine()
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
76
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
77 println "hg flow ${stream} start v${releaseVersion} --dirty".execute().text
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
78
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
79 println "hg update ${stream}/v${releaseVersion}".execute().text
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
80
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
81 println "Starting dependency lock via gradle... (please wait)"
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
82 println "cmd /c gradlew.bat deleteGlobalLock generateGlobalLock saveGlobalLock".execute().text
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
83
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
84 println 'hg commit -A release.lock -m "lock dynamic dependencies for release"'.execute().text
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
85
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
86 println "Created $releaseVersion $stream branch with locked dynamic dependencies."
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
87 println " Verify the branch and release.lock file created correctly then push the new branch."
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
88 println " If any problems, then delete repo and clone a fresh copy repository."
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
89
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
90 def checkForSnapshots() {
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
91 def lines = new File('gradle.properties').readLines() + new File('build.gradle').readLines()
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
92 def snapshots = lines.collect { it.trim() }.findAll{
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
93 it.contains('.SNAPSHOT') && !it.startsWith('version=') ||
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
94 it.contains('latest.') && (it.startsWith('compile') || it.startsWith('runtime'))
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
95 }
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
96 if (snapshots) {
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
97 println "project contains SNAPSHOT dependencies: \n\t" + snapshots.join('\n\t')
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
98 System.exit(1)
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
99 }
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
100 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
101
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
102
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
103 @TupleConstructor
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
104 @Sortable
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
105 class Version {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
106
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
107 Integer major = 0
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
108 Integer minor = 0
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
109 Integer patch = 0
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
110 Boolean snapshot = false
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
111
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
112 Version nextMajor() {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
113 new Version(major + 1, 0, 0)
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
114 }
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
115
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
116 Version nextMinor() {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
117 if (snapshot) {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
118 new Version(major, minor , 0)
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
119 } else {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
120 new Version(major, minor + 1, 0)
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
121 }
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
122 }
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
123
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
124 Version nextSnapshot() {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
125 new Version(major, minor + 1, 0,true)
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
126 }
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
127
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
128 Version nextPatch() {
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
129 new Version(major, minor, patch + 1)
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
130 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
131
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
132 String toString() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
133 "${major}.${minor}.${patch}${snapshot ? '.SNAPSHOT' : ''}"
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
134 }
208
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
135
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
136 }
f200b931ea9d add release and hgflow scripts
smith@nwoca.org
parents:
diff changeset
137
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
138
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
139 @ToString(includes=['name','shortName','buildVersion','imageId','deployName'],includeNames= true)
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
140 class BranchInfo {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
141 def name
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
142 def stream = "none"
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
143 def buildNumber = ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
144 def changeset = ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
145 def version
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
146
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
147 BranchInfo(name = null) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
148 this.name = name
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
149 if (!name) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
150 this.name = determineName() ?: ''
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
151 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
152 this.name = this.name.replace('@', '-')
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
153 determineStream()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
154 buildNumber = System.getenv('bamboo_buildNumber') ?: ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
155 changeset = System.getenv('bamboo_planRepository_revision') ?: ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
156 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
157
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
158 String getDefaultDependencyStatus() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
159 return isRelease() ? 'release' : 'integration'
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
160 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
161
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
162 private boolean isRelease() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
163 return stream in ['release', 'hotfix']
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
164 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
165
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
166 def getShortName() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
167 def result = name.contains('/') ? name.split('/')[1] : name
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
168 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
169
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
170 String getBuildVersion() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
171 def v = isRelease() ? shortName - "v": ""
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
172 return v
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
173 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
174
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
175 def Version getVersion() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
176 if (!version) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
177 if (isRelease()) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
178 version = new Version(*getBuildVersion().split('\\.')*.toInteger(), false)
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
179 } else {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
180 version = findSnapshotVersion()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
181 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
182 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
183 return version
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
184 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
185
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
186 def getImageId() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
187 (buildVersion ?: shortName.take(25)) + (buildNumber ? "-${buildNumber}" : "-0")
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
188 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
189
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
190 def getDeployName() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
191 (buildVersion ?: shortName.take(25)).toLowerCase().collectReplacements {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
192 ('a'..'z').contains(it) || ('0'..'9').contains(it) || it == "-" ? null : '-'
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
193 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
194 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
195
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
196 def getHash() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
197 generateMD5(name)
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
198 }
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
199
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
200 def generateMD5(String s) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
201 def digest = java.security.MessageDigest.getInstance("MD5")
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
202 digest.update(s.bytes);
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
203 new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
204 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
205
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
206 private findSnapshotVersion() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
207 def versions = "hg branches --closed".execute().text.split('\n').findAll {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
208 it.startsWith( 'release') || it.startsWith( 'hotfix')
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
209 }.collect {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
210 it.replaceAll('\\s+',' ').split(' ')[0].split('/')[1] - 'v'
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
211 }.collect {
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
212 new Version(*it.split('\\.')*.toInteger(),true)
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
213 }.sort { v1, v2 -> v2 <=> v1 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
214
217
49a220a1bde0 DEP-11: allow keywords to calculate release version based on current branch
smith@nwoca.org
parents: 216
diff changeset
215 return versions ? versions.first().nextSnapshot() : new Version().nextSnapshot()
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
216
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
217 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
218
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
219
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
220 def determineName() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
221 try {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
222 def branch = "hg branch".execute().text.trim()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
223 def rawParents = 'hg parents'.execute().text
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
224 def parent = rawParents.split('\n').find { it.startsWith("branch") }?.split(":")?.getAt(1)?.trim()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
225 return parent ?: branch
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
226 } catch (e) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
227 ['.hg/branch', '../.hg/branch'].findResult {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
228 new File(it).exists() ? new File(it).text : null
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
229 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
230 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
231 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
232
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
233 void determineStream() {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
234 def flowConfig = new File('.hgflow').exists() ? new File('.hgflow') : new File('../.hgflow')
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
235 if (flowConfig.exists()) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
236 def flows = new Properties()
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
237 flows.load(flowConfig.newReader())
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
238 flows.stringPropertyNames().each {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
239 if (!it.startsWith("[") && name.startsWith(flows.getProperty(it))) {
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
240 stream = it
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
241 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
242 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
243 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
244 }
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
245
b628d49d2891 DEP-11: change name of lock file for release branch. update release script to depend on new resolution and dependency locking
smith@nwoca.org
parents: 215
diff changeset
246 }