Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Add tag release command
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Dec 27, 2021
1 parent 18cc913 commit 77ac672
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ fun Project.booleanProperty(name: String) = this.findProperty(name).toString().t

fun Project.booleanEnv(name: String) = (System.getenv(name) as String?).toString().toBoolean()

task("tagRelease") {
val tagName = versioning.info.nextVersion() ?: throw IllegalStateException("unable to compute tag name")
exec {
commandLine("git", "tag", tagName)
}
exec {
commandLine("git", "push", "origin", "refs/tags/$tagName")
}
}

fun VersionInfo.nextVersion() = when {
this.tag == null && this.branch == "main" -> {
val matchResult = Regex("v(\\d+)\\.(\\d+)").matchEntire(this.lastTag ?: "")
if (matchResult != null) {
val (_, major, minor) = matchResult.groupValues
"v$major.${minor.toInt() + 1}"
} else {
null
}
}
else -> {
null
}
}

fun VersionInfo.effectiveVersion() = when {
this.tag == null && this.branch == "main" -> {
val matchResult = Regex("v(\\d+)\\.(\\d+)").matchEntire(this.lastTag ?: "")
Expand Down

0 comments on commit 77ac672

Please sign in to comment.