Skip to content

Commit

Permalink
Include project version from git in /api/v2/service/info
Browse files Browse the repository at this point in the history
The git tag should determine the project version. There
are other ways to do this but we don't want to depend on GH actions to set the version.

Here's an example json payload (of a local branch with uncommited changes) for the endpoint:

```json
{
  "compiletime": {
    "name": "MapRouletteAPI",
    "version": "4.4.5-3-gae3b68b-SNAPSHOT",
    "scalaVersion": "2.13.10",
    "sbtVersion": "1.7.2",
    "buildDate": "2023-08-15",
    "javaVersion": "11.0.20",
    "javaVendor": "Eclipse Adoptium",
    "gitCommit": "ae3b68b70410628fa6a338db977b18b85af9c06a",
    "gitCommitMessage": "Eliminate use of 'null' in TaskReviewRepository query and improve readability (#1058)",
    "gitCommitDate": "2023-08-12T19:00:34-0500",
    "gitBranch": "ljdelight/setVersionDuringBuild",
    "gitHasUncommitedChanges": true,
    "gitDescribe": "4.4.5-3-gae3b68b"
  },
  "runtime": {
    "javaVersion": "11.0.20",
    "javaVendor": "Eclipse Adoptium",
    "startDateTime": "2023-08-15T00:16:57.505786"
  }
}
```
  • Loading branch information
ljdelight committed Aug 15, 2023
1 parent ae3b68b commit e4eff60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import scala.io.Source
import scala.util.Using

name := "MapRouletteAPI"

version := "4.0.0"

scalaVersion := "2.13.10"

Universal / packageName := "MapRouletteAPI"

// Developers can run 'sbt format' to easily format their source; this is required to pass a PR build.
addCommandAlias("format", "scalafmtAll; scalafmtSbt; scalafixAll")

enablePlugins(GitVersioning)
git.useGitDescribe := true

// Setup BuildInfo plugin to write important build-time values to a generated file (org.maproulette.models.service.info.BuildInfo)
enablePlugins(BuildInfoPlugin)
buildInfoPackage := "org.maproulette.models.service.info"
Expand All @@ -32,6 +31,14 @@ buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion)
buildInfoKeys += BuildInfoKey.action("buildDate")(LocalDate.now(ZoneOffset.UTC).toString)
buildInfoKeys += BuildInfoKey.action("javaVersion")(sys.props("java.version"))
buildInfoKeys += BuildInfoKey.action("javaVendor")(sys.props("java.vendor"))
buildInfoKeys += BuildInfoKey.action("gitCommit")(git.gitHeadCommit.value)
buildInfoKeys += BuildInfoKey.action("gitCommitMessage")(
git.gitHeadMessage.value.getOrElse("Unavailable").split("\n").head
)
buildInfoKeys += BuildInfoKey.action("gitCommitDate")(git.gitHeadCommitDate.value)
buildInfoKeys += BuildInfoKey.action("gitBranch")(git.gitCurrentBranch.value)
buildInfoKeys += BuildInfoKey.action("gitHasUncommitedChanges")(git.gitUncommittedChanges.value)
buildInfoKeys += BuildInfoKey.action("gitDescribe")(git.gitDescribedVersion.value)

// Configure scalastyle. This does not run during compile, run it with 'sbt scalastyle' or 'sbt test:scalastyle'.
Compile / scalastyleConfig := baseDirectory.value / "conf/scalastyle-config.xml"
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.3")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1")

0 comments on commit e4eff60

Please sign in to comment.