Skip to content

Commit 89c427e

Browse files
authored
Fix gradle version determination breaking in some environments (#2682)
1 parent f9a5d74 commit 89c427e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

gradle/versioning.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// v0.20.0-2-g000a42a -> 0.20.0-2-g000a42a
22
ext.getTag = { ->
33
def stdout = new ByteArrayOutputStream()
4-
exec {
5-
commandLine 'git', 'describe', '--tags'
6-
standardOutput = stdout
4+
try {
5+
exec {
6+
commandLine 'git', 'describe', '--tags'
7+
standardOutput = stdout
8+
}
9+
} catch (ignored) {
10+
return "unknown"
711
}
812
return stdout.toString().trim().substring(1)
913
}
@@ -21,7 +25,11 @@ ext.getVersionName = { ->
2125

2226
// The last element of describe should start with g according to git describe format
2327
// if we are not exactly on a tag. If it doesn't - we are on a tag
24-
def (_, major, minor, patch, rc, extra, git) = (tag =~ /^(\d+)[.](\d+)[.](\d+)(?:-RC(\d+))?(-.*?)?(-g[0-9a-f]+)?$/)[0];
28+
def match = (tag =~ /^(\d+)[.](\d+)[.](\d+)(?:-RC(\d+))?(-.*?)?(-g[0-9a-f]+)?$/)
29+
if (match.size() == 0) {
30+
return "unknown"
31+
}
32+
def (_, major, minor, patch, rc, extra, git) = match[0];
2533

2634
if (git) {
2735
if (rc) {

0 commit comments

Comments
 (0)