From 7910a2f664f4528b9c0405fd5635aecf53e7597c Mon Sep 17 00:00:00 2001 From: dzmipt Date: Wed, 27 Dec 2023 00:04:48 +0100 Subject: [PATCH] add git commit number and hash --- build.gradle | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9f845233..1de075a6 100644 --- a/build.gradle +++ b/build.gradle @@ -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() } }