Allow the version to be emitted to file.
This commit is contained in:
parent
2adf6ce66d
commit
ef34c9b398
3 changed files with 31 additions and 5 deletions
|
@ -1 +1 @@
|
|||
sbt.version=1.9.8
|
||||
sbt.version=1.9.9
|
||||
|
|
|
@ -60,6 +60,13 @@ object SemVerKeys {
|
|||
"True or false depending on whether the current build is a pre-release (snapshot) build."
|
||||
)
|
||||
|
||||
/** SBT Setting that defines the filename for dumping the selected SemVer to a
|
||||
* file.
|
||||
*/
|
||||
lazy val semVerOutputFile = settingKey[Option[String]](
|
||||
"Name of the file where the calculated SemVer will be stored (if requested)."
|
||||
)
|
||||
|
||||
/** Task which emits the current and selected versions at the informational
|
||||
* log level.
|
||||
*/
|
||||
|
@ -67,4 +74,10 @@ object SemVerKeys {
|
|||
"Dump the calculated version information."
|
||||
)
|
||||
|
||||
/** Task which writes the selected SemVer to a file.
|
||||
*/
|
||||
lazy val semVerWriteVersionToFile = taskKey[Unit](
|
||||
"Write the selected SemVer to a file."
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package gs
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import sbt._
|
||||
|
||||
object SemVerPlugin extends AutoPlugin {
|
||||
|
@ -9,6 +12,8 @@ object SemVerPlugin extends AutoPlugin {
|
|||
|
||||
import autoImport._
|
||||
|
||||
val DefaultOutputFile: String = ".version"
|
||||
|
||||
// Perform all version calculations and expose as a variable.
|
||||
lazy val semVerDefaults: Seq[Setting[_]] = {
|
||||
// The latest semantic version relevant to this project, calculated by
|
||||
|
@ -46,7 +51,8 @@ object SemVerPlugin extends AutoPlugin {
|
|||
semVerCurrent := latestSemVer.toString(),
|
||||
semVerSelected := selectedSemVer.render(isSnapshot),
|
||||
semVerMajor := selectedSemVer.major,
|
||||
semVerSnapshot := isSnapshot
|
||||
semVerSnapshot := isSnapshot,
|
||||
semVerOutputFile := Some(DefaultOutputFile)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -59,6 +65,13 @@ object SemVerPlugin extends AutoPlugin {
|
|||
val log = Keys.streams.value.log
|
||||
log.info(s"[SemVer] Current: ${semVerCurrent.value}")
|
||||
log.info(s"[SemVer] Selected: ${semVerSelected.value}")
|
||||
},
|
||||
semVerWriteVersionToFile := {
|
||||
val outputFile = semVerOutputFile.value.getOrElse(DefaultOutputFile)
|
||||
Files.write(
|
||||
Paths.get(outputFile),
|
||||
semVerSelected.value.getBytes(StandardCharsets.UTF_8)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue