Skip to content

Instantly share code, notes, and snippets.

@dwijnand
Last active January 23, 2016 01:34
Show Gist options
  • Save dwijnand/d0531825717983514bd8 to your computer and use it in GitHub Desktop.
Save dwijnand/d0531825717983514bd8 to your computer and use it in GitHub Desktop.
dynver
// sbt.version = 0.13.9
lazy val dynver = taskKey[String]("Determine the dynamic version")
dynver := {
// Inspired by Mercurial's own self-versioning:
// http://www.selenic.com/hg/file/61b333b982ea/setup.py#l184
// Outputs either:
// * v1.0.0 (if building on v1.0.0 tag, w/o local changes)
// * v1.0.0+20140707 (if building on v1.0.0 tag with local changes)
// * v1.0.0+3-1234abcd (if building on commit 1234abcd: 3 commits after v1.0.0 tag, w/o local changes)
// * v1.0.0+3-1234abcd+20140707 (if building on commit 1234abcd: 3 commits after v1.0.0 tag with local changes)
// * 1234abcd (if building & there are no tags, on commit 1234abcd, w/o local changes)
// * 1234abcd+20140707 (if building & there are no tags, on commit 1234abcd with local changes)
val tstamp = "%1$tY%1$tm%1$td" format new java.util.Date
val v = ("git describe --abbrev=8 --always --dirty=+" + tstamp).!!.init
v.replaceAll("-([0-9]+)-g([0-9a-f]{8})", "+$1-$2")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment