From 77ac67277158e95a8f5c88676808cc56b2ef1943 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Mon, 27 Dec 2021 12:16:18 +0000 Subject: [PATCH] Add tag release command --- build.gradle.kts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 7aec31e6..1a057230 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 ?: "")