Skip to content

Commit

Permalink
add git commit number and hash
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Dec 26, 2023
1 parent 8cd1606 commit 7910a2f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,39 @@ def buildTime() {
return df.format(new Date())
}

def getGitRevNumber = { ->
def stdout = new ByteArrayOutputStream()
def errout = new ByteArrayOutputStream()
def hash = ""
def rev = ""
try {
exec {
commandLine 'git', 'rev-list', '--count', 'HEAD'
standardOutput = stdout
errorOutput = errout
}
rev = stdout.toString().trim()

stdout.reset()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
errorOutput = errout
}
hash = stdout.toString().trim()

} catch (Throwable e) {
println "Error getting git revision: " + e
println errout.toString()
}

if (hash == "" || rev == "") return "";
return ", commit number: $rev, hash: $hash"
}

task getBuildHash {
doLast {
file("src/build.txt").text = buildTime()
file("src/build.txt").text = buildTime() + getGitRevNumber()
}
}

Expand Down

0 comments on commit 7910a2f

Please sign in to comment.