-
Notifications
You must be signed in to change notification settings - Fork 101
/
common.gradle
43 lines (40 loc) · 1.66 KB
/
common.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
ext {
springBootWebVersion = "2.2.5.RELEASE"
hydraLabVersion = '1.0.0'
}
task NewBranch(group: 'workflow') {
doFirst {
// read branch prefix
def localProperties = new Properties()
def localPropFile = file("local.properties")
if (!localPropFile.exists()) {
localPropFile.createNewFile()
throw new RuntimeException("please provide branchPrefix in file: " + localPropFile);
}
localPropFile.withInputStream { localProperties.load(it) }
def branchPrefix = localProperties.getProperty('branchPrefix')
if (!branchPrefix) {
throw new RuntimeException("please provide branchPrefix in file: " + localPropFile);
}
// If already on temp branch ...
def branchName = new StringBuilder()
def getBranch = "git rev-parse --abbrev-ref HEAD".execute()
def serr = new StringBuilder()
getBranch.consumeProcessOutput(branchName, serr)
getBranch.waitForOrKill(2 * 1000)
println "branchName> $branchName"
def bName = branchName.toString().trim()
def middleFolder = "temporary"
if (bName.startsWith("${branchPrefix}/${middleFolder}/")) {
throw new RuntimeException("already on " + bName);
}
// checkout new branch
def newBranchName = "${branchPrefix}/${middleFolder}/${new Date().format("yyyy_MM_dd_HH_mm_ss")}"
def proc = "git checkout -b ${newBranchName}".execute()
def sout = new StringBuilder()
serr = new StringBuilder()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(5 * 1000)
println "out> $sout \nerr> $serr"
}
}