forked from jMonkeyEngine/jmonkeyengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.gradle
More file actions
132 lines (117 loc) · 5.33 KB
/
version.gradle
File metadata and controls
132 lines (117 loc) · 5.33 KB
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
128
129
130
131
132
import java.text.SimpleDateFormat
ext {
jmeRevision = 0
jmeGitHash = ""
jmeGitTag = ""
jmeShortGitHash = ""
jmeBuildDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date())
jmeBranchName = "unknown"
jmeFullVersion = "${jmeVersion}-SNAPSHOT"
jmeVersionTag="SNAPSHOT"
}
def gitOutput = { List<String> args ->
def output = providers.exec {
commandLine(['git'] + args)
ignoreExitValue = true
}
if (output.result.get().exitValue == 0) {
return output.standardOutput.asText.get().trim()
}
return ""
}
def normalizeBranchName = { String branchName ->
branchName && branchName != "HEAD" ? branchName : "unknown"
}
try {
// Users can configure behavior by setting properties on the command
// line:
//
// jmeVersionName:
// If set this will override all automatic version detection.
//
// useCommitHashAsVersionName:
// If there is no jmeVersionName set and the current commit has no
// specific tag then setting this to 'true' will cause the version to
// be the full commit ID.
//
// includeBranchInVersion:
// Set to true if a non-master branch name should be included in the automatically
// generated version.
def revisionOutput = gitOutput(['rev-list', '--count', 'HEAD'])
jmeRevision = revisionOutput ? revisionOutput.toInteger() : 0
jmeGitHash = gitOutput(['rev-parse', 'HEAD'])
jmeShortGitHash = gitOutput(['rev-parse', '--short=7', 'HEAD'])
jmeBranchName = normalizeBranchName(gitOutput(['branch', '--show-current']) ?: gitOutput(['rev-parse', '--abbrev-ref', 'HEAD']))
// This code will find an exact-match tag if the current
// commit is the same as the tag commit.
jmeGitTag = gitOutput(['describe', '--tags', '--exact-match', 'HEAD'])
def latestTag;
if( jmeGitTag ) {
latestTag = jmeGitTag;
} else {
latestTag = gitOutput(['describe', '--tags', '--abbrev=0', 'HEAD'])
println "Latest tag:" + latestTag
}
// We could enhance this with some more regex if we wanted to sanity
// check that it was formatted like our versions.
def tagVersion = latestTag ? latestTag.replaceFirst(/^v/, "") : jmeVersion;
// If the branch is not master then use the tag.
if( jmeBranchName != "master" && latestTag ) {
jmeVersion = tagVersion
}
// Parse out just the base version part. -SNAPSHOT versions
// shouldn't really include our release suffixes
def baseVersion = (jmeVersion =~/(\d+\.\d+.\d+)/)
baseVersion = baseVersion.size() > 0 ? baseVersion[0][0] : jmeVersion
if( !jmeVersionName ) {
// If there is a specific tag for the top commit then we always
// use that.
if( jmeGitTag ) {
println "Using GIT tag as version"
jmeFullVersion = tagVersion; // already cleaned up
jmeVersionTag = "" // and no SNAPSHOT suffix for an exact version tag
// Note: this will not automatically add SNAPSHOT if the user has
// local changes that they haven't committed. Technically, only
// real CI builds should be using non-SNAPSHOT versions so we may
// eventually want to change the script to always use -SNAPSHOT with
// a CI option to turn it off.
// We could also check for unstaged modified/removed files.
// def modCount = ...
// ...but that seems like a wasteful check considering only official
// version builds should not have a -SNAPSHOT.
} else if( useCommitHashAsVersionName == "true" && jmeGitHash ) {
// The user has opted to use the hash... and we actually have
// a hash.
println "Using commit ID as version"
jmeFullVersion = jmeGitHash;
jmeVersionTag = ""
} else {
println "Auto-detecting version"
jmeVersionTag = "SNAPSHOT"
if( includeBranchInVersion == "true" && jmeBranchName != "master" && jmeBranchName != "unknown" ) {
jmeFullVersion = baseVersion + "-" + jmeBranchName + "-" + jmeVersionTag;
} else {
jmeFullVersion = baseVersion + "-" + jmeVersionTag;
}
}
} else {
// Just use defaults
println "Using user-defined version"
jmeFullVersion=jmeVersionName
jmeVersionTag = "SNAPSHOT"
}
println("Revision: ${jmeRevision}")
println("Hash: ${jmeGitHash}")
println("Short Hash: ${jmeShortGitHash}")
println("Tag: ${jmeGitTag}")
println("Build Date: ${jmeBuildDate}")
println("Build Branch: ${jmeBranchName}")
println("Use commit hash as version ${useCommitHashAsVersionName}")
println("Base Version: ${baseVersion}")
println("Build Suffix: ${jmeVersionTag}")
println("Build Version: ${jmeFullVersion}")
} catch (ex) {
// Failed to get repo info
logger.warn("Failed to get repository info: " + ex.message + ". " + \
"Only partial build info will be generated.")
}