-
Notifications
You must be signed in to change notification settings - Fork 16
/
versioning.gradle
127 lines (113 loc) · 3.91 KB
/
versioning.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* ******************************************************************************
* Copyright (c) 2019, 2020 BestSolution.at and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Caks <[email protected]> - initial API and implementation
* ******************************************************************************/
def getGitHash() {
if (System.getenv("GITHUB_SHA")) {
System.getenv("GITHUB_SHA")
} else {
getLocalGitHash()
}
}
def getGitTimestamp() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '-1', '--date=iso-strict', '--format=�', 'HEAD'
standardOutput = stdout
}
return java.time.OffsetDateTime.parse(stdout.toString().trim()).toInstant()
}
def getLocalShortGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def getLocalGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
def getReleaseTag() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
ignoreExitValue true
standardOutput = stdout
}
def tag = stdout.toString().trim()
if (tag.matches('v[0-9] \\.[0-9] \\.[0-9] (\\.[a-z0-9] )?')) {
return tag
}
return null
}
def getVersion() {
def tag = getReleaseTag()
if (tag != null) {
return tag.substring(1)
} else {
return '999.0.0'
}
}
def getTimestamp() {
System.getenv('BUILD_TIMESTAMP') != null ? System.getenv('BUILD_TIMESTAMP') : toTimestamp(getGitTimestamp())
}
def getQualifier() {
if (getReleaseTag() == null)
"${getTimestamp()}-${getLocalShortGitHash()}"
else
null
}
def toTimestamp(instant) {
return java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss").withZone( ZoneId.of("UTC") ).format(instant)
}
def tmpReleaseTag = getReleaseTag()
def tmpReleaseMode = tmpReleaseTag != null
def tmpIsRelease = tmpReleaseTag != null && tmpReleaseTag.matches('v[0-9] \\.[0-9] \\.[0-9] ')
def tmpIsPreRelease = tmpReleaseTag != null && tmpReleaseTag.matches('v[0-9] \\.[0-9] \\.[0-9] \\.[a-z0-9] ')
def tmpVersion = getVersion()
def tmpTimestamp = getTimestamp()
def tmpQualifier = getQualifier()
def tmpFullVersion = tmpReleaseMode ? tmpVersion : "$tmpVersion-$tmpQualifier"
def tmpBundleVersion = tmpReleaseMode ? tmpVersion : "${tmpVersion}.$tmpQualifier"
ext {
Versioning = [
releaseTag: tmpReleaseTag,
releaseMode: tmpReleaseMode,
isRelease: tmpIsRelease,
isPreRelease: tmpIsPreRelease,
version: tmpVersion,
timestamp: tmpTimestamp,
qualifier: tmpQualifier,
fullVersion: tmpFullVersion,
bundleVersion: tmpBundleVersion,
gitSHA: getGitHash()
]
}
task showVersioning {
println "Versioning: " //${new groovy.json.JsonBuilder(Versioning).toPrettyString()}"
println "\tgitSHA: $Versioning.gitSHA"
println "\treleaseMode: $Versioning.releaseMode"
println "\tisRelease: $Versioning.isRelease"
println "\tisPreRelease: $Versioning.isPreRelease"
println "\treleaseTag: $Versioning.releaseTag"
println "\tversion: $Versioning.version"
println "\ttimestamp: $Versioning.timestamp"
println "\tqualifier: $Versioning.qualifier"
println "\tfullVersion: $Versioning.fullVersion"
println "\tbundleVersion: $Versioning.bundleVersion"
doLast {
}
}