File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
101102val 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
You can’t perform that action at this time.
0 commit comments