forked from PhotonVision/photonvision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioningHelper.gradle
42 lines (38 loc) · 1.56 KB
/
versioningHelper.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
import java.nio.file.Path
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
gradle.allprojects {
ext.getCurrentVersion = {
->
def stdout = new ByteArrayOutputStream()
String tagIsh
try {
exec {
commandLine 'git', 'describe', '--tags', "--match=v*"
standardOutput = stdout
}
tagIsh = stdout.toString().trim().toLowerCase()
} catch (Exception e) {
tagIsh = "dev-Unknown"
}
// Dev tags: v2021.1.6-3-gf922466d
// We're specifically looking to capture the middle -3-
boolean isDev = tagIsh.matches(".*-[0-9]*-g[0-9a-f]*")
if (isDev && !tagIsh.startsWith("dev-")) tagIsh = "dev-" + tagIsh
println("Picked up version: " + tagIsh)
return tagIsh
}
if (!ext.has("versionString")) {
ext.versionString = getCurrentVersion()
}
ext.writePhotonVersionFile = {File versionFileIn, Path path, String version ->
println("Writing " + version + " to " + path.toAbsolutePath().toString())
String date = DateTimeFormatter.ofPattern("yyyy-M-d hh:mm:ss").format(LocalDateTime.now())
File versionFileOut = new File(path.toAbsolutePath().toString())
versionFileOut.delete()
def read = versionFileIn.text.replace('${version}', version).replace('${date}', date)
if (!versionFileOut.parentFile.exists()) versionFileOut.parentFile.mkdirs()
if (!versionFileOut.exists()) versionFileOut.createNewFile()
versionFileOut.write(read)
}
}