forked from facebookarchive/nailgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-info.gradle
34 lines (27 loc) · 1.35 KB
/
version-info.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
project.metaClass.getVersionInfo = {
def appVersion = 'noversion'
def appRelease = 0
def appDescription = project.name
// Find out the last matching tag
final prefix = "release-${project.name}-"
final tag = "git describe --tags --long --match $prefix*".execute().text.trim()
// Look at source dirs only
final srcDirs = ['nailgun-server/src/main', 'nailgun-client/src', 'pynailgun']
if (tag) {
// Split version details
final matcher = (tag =~ "$prefix([^-]+(-RC[0-9]+)?)-[0-9]+-g[a-z0-9]+")
appVersion = matcher[0][1]
// List revisions sice the last release (incl. the release itself)
List<String> command = ['git', 'rev-list', (prefix + appVersion + '~1..HEAD').toString(), '--'] + srcDirs
ProcessBuilder pb = new ProcessBuilder(command)
final revs = pb.start().text.split()
final lastRev = revs ? "-" + revs[0].substring(0, 7) : ''
// Find out if the project is dirty
command = ['git', 'status', '--short', '--', 'src', '--'] + srcDirs
pb = new ProcessBuilder(command)
final dirty = pb.start().text.trim().length() > 0
appRelease = Math.max(0, dirty ? revs.size() : revs.size() - 1) // commit distance
appDescription = "${project.name} v$appVersion.$appRelease$lastRev"
}
return [appVersion, appRelease, appDescription]
}