Created
October 18, 2018 05:28
-
-
Save tartakynov/097452f406f9b1f4e2798cd836ff5927 to your computer and use it in GitHub Desktop.
Return version in Play application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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