-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildinfo.gradle
67 lines (55 loc) · 1.84 KB
/
buildinfo.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
//
// Add the following line to the bottom of build.gradle:
//
// apply from: 'buildinfo.gradle'
//
tasks.register("writeBuildInfo") {
// Write the current date/time
def date = new Date()
def filetxt = date.toString() + '\n'
// Define an output stream to write to instead of terminal
def stdout = new ByteArrayOutputStream()
// Execute the git command to get the Fetch remote repository
exec {
commandLine "git", "remote", "show", "-n", "origin"
// Write to the output stream instead of terminal
standardOutput = stdout
}
def lines = stdout.toString().split("\n")
def repo = "unknown"
for (int i = 0; i < lines.length; i++) {
if( lines[i].contains( "Fetch" ) ) {
repo = lines[i];
break;
}
}
lines = repo.split("/");
if( lines.length > 1 ) {
repo = lines[ lines.length - 2 ] + '/' + lines[ lines.length - 1 ];
}
filetxt += repo + '\n'
stdout.reset()
// Execute the git command to get the tag or branch
exec {
commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
// Write to the output stream instead of terminal
standardOutput = stdout
}
filetxt += stdout.toString().trim() + '\n'
stdout.reset()
// Execute the git command to get the version/commit info
exec {
commandLine "git", "describe", "--tags", "--always", "--dirty"
// Write to the output stream instead of terminal
standardOutput = stdout
}
filetxt += stdout.toString().trim()
// Create a new file
new File(
// Join project directory and deploy directory
projectDir.toString() + "/src/main/deploy",
// File name to write to
"buildinfo.txt"
).text = filetxt // Set the contents of the file to the variable branch
}
deploy.targets.roborio.artifacts.frcStaticFileDeploy.dependsOn(writeBuildInfo)