Last active
April 13, 2020 21:49
-
-
Save ChrisAcrobat/f2a50096d9154b00859667807d1eba8a to your computer and use it in GitHub Desktop.
Git and date based version name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def checkIfTracked = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'status', '--porcelain' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim().equals("") ? "" : "-MODIFIED" | |
} | |
def getGitCommitDate = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'show', '-s', '--format=%cd' | |
standardOutput = stdout | |
} | |
return new Date(stdout.toString().trim()) | |
} | |
def getGitMonthCommitIndex = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-list', '--count', 'HEAD', '--since="' + getGitCommitDate().format("yyyy-MM") + '-01"', '--before="' + getGitCommitDate().format("yyyy-MM-dd") + '"' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim() | |
} | |
def getGitBranch = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD' | |
standardOutput = stdout | |
} | |
return stdout.toString().trim().equals("master") ? "" : (stdout.toString().trim().equals("develop") ? "-beta" : "-" + stdout.toString().trim().replace("feature/", "").replace("/", "-")) | |
} | |
def getVersion = { -> | |
// Source: https://gist.github.com/ChrisAcrobat/f2a50096d9154b00859667807d1eba8a | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'show', '-s', '--format=%cd' | |
standardOutput = stdout | |
} | |
def monthCount = getGitMonthCommitIndex() | |
def branch = getGitBranch() | |
return getGitCommitDate().format("yy.MM") + "." + monthCount + branch + checkIfTracked() | |
} | |
version getVersion() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment