Skip to content

Commit

Permalink
Change version to use tag if available
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed May 24, 2023
1 parent 0177aae commit 7d9277e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,29 @@ trait ReleaseModule extends JavaModule {
/** Get the commit shorthash at the HEAD of this branch .*/
private def shortHash: String = gitHead.take(7)

/** The current tag of the currently checked out commit, if any. */
def currentTag: Try[String] = Try(git("describe", "--exact-match", "--tags", "--always", gitHead))

/** The hash of the last tagged commit. */
private def hashOfLastTag: Try[String] = Try(git("rev-list", "--tags", "--max-count=1"))

/** The last tag of the currently checked out branch, if any. */
def lastTag: Try[String] = hashOfLastTag match {
case Success(hash) => Try(git("describe", "--abbrev=0", "--tags", "--always", hash))
case Failure(e) => Failure(e)
}

/** If the Git repository is left in a dirty state. */
private def dirty: Boolean = git("status", "--porcelain").nonEmpty

private def today: String = new SimpleDateFormat("yyyyMMdd").format(new Date())

/** The implementation version. */
private def implementationVersion = T input {
val prefix = s"${today}-${shortHash}"
if (dirty) s"${prefix}-dirty" else prefix
private def implementationVersion = T.input {
val prefix: String = (currentTag, lastTag) match {
case (Success(_currentTag), _) => _currentTag
case (Failure(_), Success(_lastTag)) => _lastTag + "-" + shortHash
case (_, _) => shortHash
}
prefix + (if (dirty) "-dirty" else "")
}

/** The version string `Target`. */
Expand Down Expand Up @@ -90,8 +104,8 @@ object tools extends CommonModule with PublishModule with ReleaseModule {
def ivyDeps = Agg(
ivy"org.scala-lang:scala-compiler:${scalaVersion()}",
ivy"com.fulcrumgenomics:fgbio_2.13:1.5.0".excludeOrg(orgsToExclude:_*),
ivy"org.xerial.snappy:snappy-java:1.1.8.4"
)
ivy"org.xerial.snappy:snappy-java:1.1.8.4"
)

object test extends Tests {
def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.1.0")
Expand Down

0 comments on commit 7d9277e

Please sign in to comment.