Skip to content

Instantly share code, notes, and snippets.

@topriddy
Created November 12, 2019 18:46
Show Gist options
  • Save topriddy/80f29fadc4c098b4b349ee565cabbc51 to your computer and use it in GitHub Desktop.
Save topriddy/80f29fadc4c098b4b349ee565cabbc51 to your computer and use it in GitHub Desktop.
apply plugin: 'org.ajoberstar.grgit'
task doVersioning() {
if (version == '') {
def timestamp = new Date().format("yyyyMMddHHmmss")
def githash = "${grgit.head().abbreviatedId}"
def currentBranchName = branch ?: grgit.branch.current().name
def shortBranchName = ["feature", "experiment", "spike", "bugfix", "hotfix"].find {
currentBranchName.startsWith(it)
}
if (currentBranchName == "master") shortBranchName = "master"
if (currentBranchName == "develop") shortBranchName = "develop"
if (shortBranchName == null) shortBranchName = "feature"
version = "${shortBranchName}-${githash}-${timestamp}"
shortVersion = "${githash}-${timestamp}"
new File("$projectDir/project-name.properties").text = "dockerTag=${version}" + "\n" + "shortVersion=${shortVersion}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment