From 43c68ba38f7dc33efdbf38b12fb11e8a3db7c031 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 26 Feb 2021 13:53:21 +0000 Subject: BuildInfo support and smart version --- build.sc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'build.sc') diff --git a/build.sc b/build.sc index 69cc6f7..2209baf 100644 --- a/build.sc +++ b/build.sc @@ -2,7 +2,10 @@ import mill._ import mill.scalalib._ import scalafmt._ -object server extends ScalaModule with ScalafmtModule { +import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION` +import mill.contrib.buildinfo.BuildInfo + +object server extends ScalaModule with ScalafmtModule with BuildInfo { def scalaVersion = "2.13.5" def scalacOptions = Seq( @@ -30,6 +33,32 @@ object server extends ScalaModule with ScalafmtModule { super.compile() } + def gitHead = T.input { os.proc('git, "rev-parse", "HEAD").call().out.trim } + + def getVersion = T.input { + val tag = try Option( + os.proc('git, 'describe, "--exact-match", "--tags", "--always", gitHead()).call().out.trim + ) + catch { case e => None } + + tag match { + case Some(t) => t + case None => + val latestTaggedVersion = os.proc('git, 'describe, "--abbrev=0", "--always", "--tags").call().out.trim + val latestCommit = gitHead().take(6) + s"$latestTaggedVersion-$latestCommit" + } + } + + val name = "spacebeans" + def buildInfoMembers: T[Map[String, String]] = T { + Map( + "name" -> name, + "version" -> getVersion() + ) + } + def buildInfoPackageName = Some("net.usebox.gemini.server") + object test extends Tests with ScalafmtModule { def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.2.2") def testFrameworks = Seq("org.scalatest.tools.Framework") -- cgit v1.2.3