From 8ea92ff5fd675432408179b958f8cebd8da87881 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 1 Sep 2022 09:17:34 +0200 Subject: [PATCH 1/4] New format option `appendSnapshot` --- .../tobiasroeser/mill/vcs/version/VcsState.scala | 13 +++++++++---- .../mill/vcs/version/VcsStateSpec.scala | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala index d7a0fec..8ecdfdf 100644 --- a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala +++ b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala @@ -17,17 +17,20 @@ case class VcsState( revHashDigits: Int = 6, dirtySep: String = "-DIRTY", dirtyHashDigits: Int = 8, - tagModifier: String => String = stripV + tagModifier: String => String = stripV, + appendSnapshot: String = "" ): String = { val versionPart = tagModifier(lastTag.getOrElse(noTagFallback)) - val commitCountPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) { + val isUntagged = lastTag.isEmpty || commitsSinceLastTag > 0 + + val commitCountPart = if (isUntagged) { s"$countSep${if (commitCountPad > 0) { (10000000000000L + commitsSinceLastTag).toString().substring(14 - commitCountPad, 14) } else commitsSinceLastTag}" } else "" - val revisionPart = if (lastTag.isEmpty || commitsSinceLastTag > 0) { + val revisionPart = if (isUntagged) { s"$revSep${currentRevision.take(revHashDigits)}" } else "" @@ -36,7 +39,9 @@ case class VcsState( case Some(d) => dirtySep + d.take(dirtyHashDigits) } - s"$versionPart$commitCountPart$revisionPart$dirtyPart" + val snapshotSuffix = if (isUntagged) appendSnapshot else "" + + s"$versionPart$commitCountPart$revisionPart$dirtyPart$snapshotSuffix" } /** diff --git a/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala b/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala index 143a023..75ddfad 100644 --- a/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala +++ b/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala @@ -50,7 +50,21 @@ class VcsStateSpec extends AnyFreeSpec { case t => t }) === "0.7.3v" ) + } + "should append a -SNAPSHOT suffix" in { + assert( + state("0.7.3", 0, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") + .format(appendSnapshot = "-SNAPSHOT") === "0.7.3" + ) + assert( + state("0.7.3", 4, "a6ea44d3726", "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") + .format(appendSnapshot = "-SNAPSHOT") === "0.7.3-4-61568e-DIRTYa6ea44d3-SNAPSHOT" + ) + assert( + state("0.7.3", 4, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") + .format(appendSnapshot = "-SNAPSHOT") === "0.7.3-4-61568e-SNAPSHOT" + ) } "Example format configs" - { From 2a24f187400f2f1bd48d7f282d1f5fac21546bc6 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 1 Sep 2022 09:21:49 +0200 Subject: [PATCH 2/4] Updated readme --- README.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.adoc b/README.adoc index d88c264..f219d57 100644 --- a/README.adoc +++ b/README.adoc @@ -58,6 +58,7 @@ The `format` method has the following options: * `dirtySep: String = "-DIRTY"` - will be printed before the dirty hash if the local repository is in modified state * `dirtyHashDigits: Int = 8` - the number of digits to be used for the dirty hash * `tagModifier: String => String` - allows to modify the git tag (By default this strips a leading `v` if one exists. e.g. v1.2.3 -> 1.2.3) +* `appendSnapshot: String = "" - will append the given string at the end of the version when the current revision is not tagged (e.g. use with `"-SNAPSHOT"` to publish to Maven Snapshot repositories) When used with its defaults, the outcome is identical to the version scheme used by mill. From bce4d633734ea283235a245acf1ec501d7d60370 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 1 Sep 2022 09:45:36 +0200 Subject: [PATCH 3/4] Added binary compatibility shim --- .../mill/vcs/version/VcsState.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala index 60c4176..0849af3 100644 --- a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala +++ b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala @@ -57,6 +57,28 @@ case class VcsState( case t => t } + @deprecated("Binary compatibility shim. Use other overload instead.", "mill-vcs-verison after 0.2.0") + private[version] def format( + noTagFallback: String, + countSep: String, + commitCountPad: Byte, + revSep: String, + revHashDigits: Int, + dirtySep: String, + dirtyHashDigits: Int, + tagModifier: String => String + ): String = format( + noTagFallback = noTagFallback, + countSep = countSep, + commitCountPad = commitCountPad, + revSep = revSep, + revHashDigits = revHashDigits, + dirtySep = dirtySep, + dirtyHashDigits = dirtyHashDigits, + tagModifier = tagModifier, + appendSnapshot = "" + ) + } object VcsState { From eac279055fc682a2bc7dd1a7944cbf45457ed41b Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Thu, 1 Sep 2022 11:00:58 +0200 Subject: [PATCH 4/4] Renamed new parameter to untaggedSuffix --- README.adoc | 4 ++-- core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala | 9 +++++---- .../de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index daf9fee..975a71f 100644 --- a/README.adoc +++ b/README.adoc @@ -58,9 +58,9 @@ The `format` method has the following options: * `dirtySep: String = "-DIRTY"` - will be printed before the dirty hash if the local repository is in modified state * `dirtyHashDigits: Int = 8` - the number of digits to be used for the dirty hash * `tagModifier: String => String` - allows to modify the git tag (By default this strips a leading `v` if one exists. e.g. v1.2.3 -> 1.2.3) -* `appendSnapshot: String = "" - will append the given string at the end of the version when the current revision is not tagged (e.g. use with `"-SNAPSHOT"` to publish to Maven Snapshot repositories) +* `untaggedSuffix: String = "" - will append the given string at the end of the version when the current revision is not tagged (e.g. use with `"-SNAPSHOT"` to publish to Maven Snapshot repositories) -When used with its defaults, the outcome is identical to the version scheme used by mill. +When used with its defaults, the outcome is identical to the version scheme used by Mill. == Download diff --git a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala index 0849af3..96db8fb 100644 --- a/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala +++ b/core/src/de/tobiasroeser/mill/vcs/version/VcsState.scala @@ -18,7 +18,7 @@ case class VcsState( dirtySep: String = "-DIRTY", dirtyHashDigits: Int = 8, tagModifier: String => String = stripV, - appendSnapshot: String = "" + untaggedSuffix: String = "" ): String = { val versionPart = tagModifier(lastTag.getOrElse(noTagFallback)) @@ -27,7 +27,8 @@ case class VcsState( val commitCountPart = if (isUntagged) { s"$countSep${if (commitCountPad > 0) { (10000000000000L + commitsSinceLastTag).toString().substring(14 - commitCountPad, 14) - } else if (commitCountPad == 0) commitsSinceLastTag else ""}" + } else if (commitCountPad == 0) commitsSinceLastTag + else ""}" } else "" val revisionPart = if (isUntagged) { @@ -39,7 +40,7 @@ case class VcsState( case Some(d) => dirtySep + d.take(dirtyHashDigits) } - val snapshotSuffix = if (isUntagged) appendSnapshot else "" + val snapshotSuffix = if (isUntagged) untaggedSuffix else "" s"$versionPart$commitCountPart$revisionPart$dirtyPart$snapshotSuffix" } @@ -76,7 +77,7 @@ case class VcsState( dirtySep = dirtySep, dirtyHashDigits = dirtyHashDigits, tagModifier = tagModifier, - appendSnapshot = "" + untaggedSuffix = "" ) } diff --git a/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala b/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala index 3d5b2a2..53d47c8 100644 --- a/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala +++ b/core/test/src/de/tobiasroeser/mill/vcs/version/VcsStateSpec.scala @@ -66,15 +66,15 @@ class VcsStateSpec extends AnyFreeSpec { "should append a -SNAPSHOT suffix" in { assert( state("0.7.3", 0, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") - .format(appendSnapshot = "-SNAPSHOT") === "0.7.3" + .format(untaggedSuffix = "-SNAPSHOT") === "0.7.3" ) assert( state("0.7.3", 4, "a6ea44d3726", "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") - .format(appendSnapshot = "-SNAPSHOT") === "0.7.3-4-61568e-DIRTYa6ea44d3-SNAPSHOT" + .format(untaggedSuffix = "-SNAPSHOT") === "0.7.3-4-61568e-DIRTYa6ea44d3-SNAPSHOT" ) assert( state("0.7.3", 4, null, "61568ec80f2465f3f01ea2c7e92273f4fbf94b01") - .format(appendSnapshot = "-SNAPSHOT") === "0.7.3-4-61568e-SNAPSHOT" + .format(untaggedSuffix = "-SNAPSHOT") === "0.7.3-4-61568e-SNAPSHOT" ) }