File tree 2 files changed +7
-3
lines changed
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 {
29
29
description = " prints the project version"
30
30
group = " help"
31
31
val version = providers.provider { project.version }
32
+ inputs.property(" version" , version)
33
+ outputs.cacheIf(" logging task, it should always run" ) { false }
32
34
doLast {
33
35
logger.quiet(" ${version.orNull} " )
34
36
}
Original file line number Diff line number Diff line change @@ -96,7 +96,8 @@ val currentCommitHash: Provider<String> =
96
96
isIgnoreExitValue = true
97
97
}.standardOutput.asText.map { it.trim() }
98
98
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]*))""" )
100
101
101
102
val gitVersion: Provider <String > =
102
103
gitDescribe.zip(currentBranchName) { described, branch ->
@@ -107,8 +108,9 @@ val gitVersion: Provider<String> =
107
108
} else {
108
109
val descriptions = described.split(" -" )
109
110
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
112
114
}
113
115
}
114
116
You can’t perform that action at this time.
0 commit comments