Skip to content

Commit 0e2829d

Browse files
committed
remove leading 'v' from version, and tidy up gitVersion logic
1 parent dcee1f5 commit 0e2829d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ val projectVersion by tasks.registering {
2929
description = "prints the project version"
3030
group = "help"
3131
val version = providers.provider { project.version }
32+
inputs.property("version", version)
33+
outputs.cacheIf("logging task, it should always run") { false }
3234
doLast {
3335
logger.quiet("${version.orNull}")
3436
}

settings.gradle.kts

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ val currentCommitHash: Provider<String> =
9696
isIgnoreExitValue = true
9797
}.standardOutput.asText.map { it.trim() }
9898

99-
val semverRegex = Regex("""v(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)""")
99+
/** Match simple SemVer tags. The first group is the `major.minor.patch` digits. */
100+
val semverRegex = Regex("""v((?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*))""")
100101

101102
val gitVersion: Provider<String> =
102103
gitDescribe.zip(currentBranchName) { described, branch ->
@@ -107,8 +108,9 @@ val gitVersion: Provider<String> =
107108
} else {
108109
val descriptions = described.split("-")
109110
val head = descriptions.singleOrNull() ?: ""
110-
val headIsVersioned = head.matches(semverRegex)
111-
if (headIsVersioned) head else currentCommitHash.get() // fall back to using the git commit hash
111+
// drop the leading `v`, try to find the `major.minor.patch` digits group
112+
val headVersion = semverRegex.matchEntire(head)?.groupValues?.last()
113+
headVersion ?: currentCommitHash.get() // fall back to using the git commit hash
112114
}
113115
}
114116

0 commit comments

Comments
 (0)