aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2021-02-26 13:53:21 +0000
committerJuan J. Martinez <jjm@usebox.net>2021-07-22 19:49:49 +0100
commit43c68ba38f7dc33efdbf38b12fb11e8a3db7c031 (patch)
treec238a0f79a1eb9225fc045e45cd3996241b38dfd
parenta14cafa19bb8b78722775fa3fee3b9987813d5b6 (diff)
downloadspacebeans-43c68ba38f7dc33efdbf38b12fb11e8a3db7c031.tar.gz
spacebeans-43c68ba38f7dc33efdbf38b12fb11e8a3db7c031.zip
BuildInfo support and smart version
-rw-r--r--build.sc31
-rw-r--r--server/src/net/usebox/gemini/server/ServerApp.scala4
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
) {
(