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 +++++++++++++++++++++- .../src/net/usebox/gemini/server/ServerApp.scala | 4 +-- 2 files changed, 32 insertions(+), 3 deletions(-) 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") diff --git a/server/src/net/usebox/gemini/server/ServerApp.scala b/server/src/net/usebox/gemini/server/ServerApp.scala index cff8553..068ea6b 100644 --- a/server/src/net/usebox/gemini/server/ServerApp.scala +++ b/server/src/net/usebox/gemini/server/ServerApp.scala @@ -10,7 +10,7 @@ object ServerApp { private val logger = getLogger val appName = "SpaceBeans Gemini Server" - val version = "1.0.1" + val version = BuildInfo.version val defConfFile = "/etc/spacebeans.conf" case class ServerOpts( @@ -20,7 +20,7 @@ object ServerApp { val opts: Command[ServerOpts] = Command( - name = "server", + name = BuildInfo.name, header = appName ) { ( -- cgit v1.2.3