forked from sbt/sbt-dynver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes sbt#5 Added a `dynverSeparator` setting so that it can be overridden for use with docker images in an easier to understand manner than is currently possible.
- Loading branch information
Showing
8 changed files
with
146 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import scala.sys.process.stringToProcess | ||
|
||
dynverSeparator in ThisBuild := "-" | ||
|
||
def tstamp = Def.setting(sbtdynver.DynVer timestamp dynverCurrentDate.value) | ||
def headSha = { | ||
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log) | ||
Def.task("git rev-parse --short=8 HEAD".!!(streams.value.log).trim) | ||
} | ||
|
||
def check(a: String, e: String) = assert(a == e, s"Version mismatch: Expected $e, Incoming $a") | ||
|
||
TaskKey[Unit]("checkNotAGitRepo") := check(version.value, s"HEAD-${tstamp.value}") | ||
TaskKey[Unit]("checkNoCommits") := check(version.value, s"HEAD-${tstamp.value}") | ||
TaskKey[Unit]("checkOnCommit") := check(version.value, s"1-${headSha.value}") | ||
TaskKey[Unit]("checkOnCommitDirty") := check(version.value, s"1-${headSha.value}-${tstamp.value}") | ||
TaskKey[Unit]("checkOnTag") := check(version.value, s"1.0.0") | ||
TaskKey[Unit]("checkOnTagDirty") := check(version.value, s"1.0.0-0-${headSha.value}-${tstamp.value}") | ||
TaskKey[Unit]("checkOnTagAndCommit") := check(version.value, s"1.0.0-1-${headSha.value}") | ||
TaskKey[Unit]("checkOnTagAndCommitDirty") := check(version.value, s"1.0.0-1-${headSha.value}-${tstamp.value}") | ||
|
||
TaskKey[Unit]("gitInitSetup") := { | ||
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log) | ||
"git init".!!(streams.value.log) | ||
"git config user.email dynver@mailinator.com".!!(streams.value.log) | ||
"git config user.name dynver".!!(streams.value.log) | ||
} | ||
|
||
TaskKey[Unit]("gitAdd") := { | ||
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log) | ||
"git add .".!!(streams.value.log) | ||
} | ||
TaskKey[Unit]("gitCommit") := { | ||
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log) | ||
"git commit -am1".!!(streams.value.log) | ||
} | ||
TaskKey[Unit]("gitTag") := { | ||
implicit def log2log(log: Logger): scala.sys.process.ProcessLogger = sbtLoggerToScalaSysProcessLogger(log) | ||
"git tag -a v1.0.0 -m1.0.0".!!(streams.value.log) | ||
} | ||
|
||
TaskKey[Unit]("dirty") := { | ||
import java.nio.file._, StandardOpenOption._ | ||
import scala.collection.JavaConverters._ | ||
Files.write(baseDirectory.value.toPath.resolve("f.txt"), Seq("1").asJava, CREATE, APPEND) | ||
} | ||
|
||
def sbtLoggerToScalaSysProcessLogger(log: Logger): scala.sys.process.ProcessLogger = | ||
new scala.sys.process.ProcessLogger { | ||
def buffer[T](f: => T): T = f | ||
def err(s: => String): Unit = log info s | ||
def out(s: => String): Unit = log error s | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sys.props.get("plugin.version") match { | ||
case Some(x) => addSbtPlugin("com.dwijnand" % "sbt-dynver" % x) | ||
case _ => sys.error("""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
> checkNotAGitRepo | ||
|
||
> gitInitSetup | ||
> reload | ||
> checkNoCommits | ||
|
||
> dirty | ||
> gitAdd | ||
> gitCommit | ||
> reload | ||
> checkOnCommit | ||
|
||
> dirty | ||
> reload | ||
> checkOnCommitDirty | ||
|
||
> gitCommit | ||
> gitTag | ||
> reload | ||
> checkOnTag | ||
|
||
> dirty | ||
> reload | ||
> checkOnTagDirty | ||
|
||
> gitCommit | ||
> reload | ||
> checkOnTagAndCommit | ||
|
||
> dirty | ||
> reload | ||
> checkOnTagAndCommitDirty |
This file contains 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
This file contains 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
This file contains 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