Skip to content

Commit

Permalink
Merge pull request #255 from eed3si9n/wip/reproduce_dynverAssertTagVe…
Browse files Browse the repository at this point in the history
…rsion_null

Fix dynverAssertTagVersion
  • Loading branch information
eed3si9n authored May 1, 2023
2 parents 48134c2 + 289d3c7 commit a035967
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
22 changes: 14 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ lazy val scalacOptions212 = Seq(
)

inThisBuild(List(
scalaVersion := scala2_12,
organization := "com.github.sbt",
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
description := "An sbt plugin to dynamically set your version from git",
developers := List(Developer("dwijnand", "Dale Wijnand", "dale wijnand gmail com", url("https://dwijnand.com"))),
startYear := Some(2016),
homepage := scmInfo.value map (_.browseUrl),
scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-dynver"), "scm:git:[email protected]:sbt/sbt-dynver.git")),
scalaVersion := scala2_12,
organization := "com.github.sbt",
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
description := "An sbt plugin to dynamically set your version from git",
developers := List(Developer("dwijnand", "Dale Wijnand", "dale wijnand gmail com", url("https://dwijnand.com"))),
startYear := Some(2016),
homepage := scmInfo.value map (_.browseUrl),
scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-dynver"), "scm:git:[email protected]:sbt/sbt-dynver.git")),
dynverSonatypeSnapshots := true,
version := {
val orig = version.value
if (orig.endsWith("-SNAPSHOT")) "5.0.1-SNAPSHOT"
else orig
},

scalacOptions ++= Seq(
"-encoding",
Expand Down
10 changes: 5 additions & 5 deletions sbtdynver/src/main/scala/sbtdynver/DynVerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ object DynVerPlugin extends AutoPlugin {
dynverAssertVersion := assertVersionImpl.value,
)

private val getVersion = Def.setting { (date: Date, out: Option[GitDescribeOutput]) =>
private lazy val getVersion = Def.setting { (date: Date, out: Option[GitDescribeOutput]) =>
out.getVersion(date, dynverSeparator.value, dynverSonatypeSnapshots.value)
}

private val tagPrefix = Def.setting {
private lazy val tagPrefix = Def.setting {
val vTagPrefix = dynverVTagPrefix.value
val tagPrefix = dynverTagPrefix.?.value.getOrElse(if (vTagPrefix) "v" else "")
assert(vTagPrefix ^ tagPrefix != "v", s"Incoherence: dynverTagPrefix=$tagPrefix vs dynverVTagPrefix=$vTagPrefix")
tagPrefix
}

private val assertTagVersion = Def.setting {
private lazy val assertTagVersion = Def.setting {
dynverGitDescribeOutput.value.assertTagVersion(version.value)
}

private val assertVersionImpl = Def.task {
private lazy val assertVersionImpl = Def.task {
val v = version.value
val dv = dynver.value
if (!dynverCheckVersion.value)
sys.error(s"Version and dynver mismatch - version: $v, dynver: $dv")
}

private val buildBase = ThisBuild / baseDirectory
private lazy val buildBase = ThisBuild / baseDirectory
}
28 changes: 28 additions & 0 deletions sbtdynver/src/sbt-test/dynver/assert-tag-version-ok/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import scala.sys.process.stringToProcess
import scala.sys.process.ProcessLogger

TaskKey[Unit]("gitInitSetup") := {
implicit def log2log(log: Logger): ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git init".!!(streams.value.log)
"git config user.email [email protected]".!!(streams.value.log)
"git config user.name dynver".!!(streams.value.log)
}

TaskKey[Unit]("gitAdd") := {
implicit def log2log(log: Logger): ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git add .".!!(streams.value.log)
}
TaskKey[Unit]("gitCommit") := {
implicit def log2log(log: Logger): ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git commit -am1".!!(streams.value.log)
}
TaskKey[Unit]("gitTag") := {
implicit def log2log(log: Logger): ProcessLogger = sbtLoggerToScalaSysProcessLogger(log)
"git tag -a v1.0.0 -m1.0.0".!!(streams.value.log)
}
def sbtLoggerToScalaSysProcessLogger(log: Logger): ProcessLogger =
new ProcessLogger {
def buffer[T](f: => T): T = f
def err(s: => String): Unit = log info s
def out(s: => String): Unit = log error s
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-dynver" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
7 changes: 7 additions & 0 deletions sbtdynver/src/sbt-test/dynver/assert-tag-version-ok/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> gitInitSetup
> gitAdd
> gitCommit
> gitTag
$ copy-file changes/build.sbt build.sbt
> reload
> about

0 comments on commit a035967

Please sign in to comment.