Skip to content

Instantly share code, notes, and snippets.

@tartakynov
Created October 18, 2018 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tartakynov/097452f406f9b1f4e2798cd836ff5927 to your computer and use it in GitHub Desktop.
Save tartakynov/097452f406f9b1f4e2798cd836ff5927 to your computer and use it in GitHub Desktop.
Return version in Play application
import scala.sys.process
import scala.util.Try
import com.typesafe.sbt.web.Import._
import play.sbt.PlayScala
import sbt._
import sbt.Keys._
/**
* Adds /version.txt into Play static assets
*/
object WebVersion extends AutoPlugin {
override def requires: sbt.Plugins = PlayScala
override lazy val projectSettings: Seq[Def.Setting[_]] = Seq(
resourceGenerators in Assets += Def.task {
val commit = Try(process.Process("git rev-parse HEAD").!!).toOption.map(rev => s"git-commit=$rev")
val content = Seq(Some(s"version=${version.value}"), commit).flatten.mkString(" ")
val file = WebKeys.webTarget.value / "version" / "version.txt"
IO.write(file, content)
Seq(file)
}.taskValue,
managedResourceDirectories in Assets += WebKeys.webTarget.value / "version"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment