From f8ed0c6fa872dbba3a8cfdba608e615de443f495 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Sun, 22 Oct 2023 10:18:27 +0200 Subject: [PATCH] Calculate snapshot version properly --- build.sbt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 5452489..f7cf426 100644 --- a/build.sbt +++ b/build.sbt @@ -43,10 +43,21 @@ ThisBuild / githubWorkflowPublish := Seq( ) ) ) -ThisBuild / version := { - val orig = (ThisBuild / version).value - if (orig.endsWith("-SNAPSHOT")) orig.split("""\+""").head + "-SNAPSHOT" - else orig + +// So that publishLocal doesn't continuously create new versions +def versionFmt(out: sbtdynver.GitDescribeOutput): String = { + val snapshotSuffix = if + (out.isSnapshot()) "-SNAPSHOT" + else "" + out.ref.dropPrefix + snapshotSuffix +} + +def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}" + +ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value)) +ThisBuild / dynver := { + val d = new java.util.Date + sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d)) } sbtPlugin := true