forked from jeakfrw/jeak-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-release.gradle
41 lines (35 loc) · 1.54 KB
/
pre-release.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
project.ext.getPreReleaseTag = { ->
println "Getting git tag for pre-release version."
def logOut = new StringBuilder(), logErr = new StringBuilder()
def logProc = "git log -n1 --pretty='%h'".execute()
logProc.consumeProcessOutput(logOut, logErr);
logProc.waitForOrKill(1000)
if (logProc.exitValue() != 0 || logErr.length() > 0) {
throw new InvalidUserDataException("Failed to get git ref-log")
}
def gitLog = logOut.toString()
println "Ref-log says: " + gitLog
def logPattern = ~/'([a-z0-9]+)'/
def logMatcher = logPattern.matcher(gitLog)
if (!logMatcher.find()) {
throw new InvalidUserDataException("Failed to find commit-ref in log!")
}
gitLog = logMatcher.group(1)
def describeOut = new StringBuilder(), describeErr = new StringBuilder()
def describeProc = "git describe --exact-match --tags $gitLog".execute()
describeProc.consumeProcessOutput(describeOut, describeErr)
describeProc.waitForOrKill(1000)
if (describeProc.exitValue() != 0 || describeErr.length() > 0) {
println "Failed to get git tag: " + describeErr.toString()
throw new InvalidUserDataException("Current revision has no tag!")
}
def tagName = describeOut.toString()
def rcPattern = ~/(\d+\.\d+\.\d+-rc\.\d+)/
def matcher = rcPattern.matcher(tagName)
if (!matcher.find()) {
throw new InvalidUserDataException("Current revision is not a release candidate tag! Found: $tagName")
}
def tag = matcher.group(1)
println "Found tag: " + tag
return tag
}