Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions buildSrc/src/main/groovy/wtmp.versioning-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import java.time.LocalDate
import java.time.format.DateTimeFormatter


plugins {
id "com.palantir.git-version"
id "org.ajoberstar.grgit"
}

def dateVersion() {
def fmt = DateTimeFormatter.ofPattern("yyyy.MM.dd") // format: YYYY.MM.DD
return LocalDate.now().format(fmt)
}

version = dateVersion()

tasks.register("showGit") {
doFirst {
def gitInfo = versionDetails()
Expand All @@ -14,49 +25,12 @@ tasks.register("showGit") {
}
}

def versionLabel(gitInfo) {
def branch = gitInfo.branchName // all branches are snapshots, only tags get released
if (branch == null && !"$System.env.CI_COMMIT_BRANCH".isEmpty()) {
branch = "$System.env.CI_COMMIT_BRANCH" // Gitlab CI checks out a commit, not a branch. Grab the branch name from the env vars it sets
}
def tag = gitInfo.lastTag
// tag is returned as is. Branch may need cleanup
return (branch == null || branch == "null" || branch.isEmpty()) ? tag : branch.replace("/","-") + "-SNAPSHOT"
}

/**
* When running on the Build System (eg TeamCity) will get BUILD_NUMBER
* Otherwise, gets the current commit (and status)
*/
String getBuildID() {
if(project.version.contains("-SNAPSHOT")) {
def buildNum = System.env.BUILD_NUMBER
if (!buildNum?.trim()) {
buildNum = "-${grgit.head().abbreviatedId}"
def clean = grgit.status().isClean()
if (!clean) {
buildNum += "+"
}
} else {
buildNum = "." + buildNum
}
return buildNum
} else {
// If dirty, return "+"
return grgit.status().isClean() ? "" : "+"
}
}

String getShortVersionName() {
String shortVersion = project.version
if(shortVersion.contains("-SNAPSHOT")) {
shortVersion = shortVersion.substring(0, shortVersion.indexOf("-SNAPSHOT"))
}
return shortVersion
return project.version.toString()
}

String getConventionVersion() {
return versionLabel(versionDetails())
return project.version.toString()
}

project.getExtensions().add("versionConventions", this)