Last active
June 1, 2016 22:08
-
-
Save knshiro/8e8b150281213beaffe3 to your computer and use it in GitHub Desktop.
Make sbt-release work with sbt-git versioning.
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
import sbtrelease._ | |
import ReleaseKeys._ | |
import Utilities._ | |
import ReleaseStateTransformations._ | |
val gitVersionString = """enablePlugins(GitVersioning) | |
git.baseVersion := "%s"""" | |
def writeVersion(st: State, versionString: String) { | |
val file = st.extract.get(releaseVersionFile) | |
IO.write(file, versionString) | |
} | |
val globalVersionString = "version in ThisBuild := \"%s\"" | |
val versionString = "version := \"%s\"" | |
def setVersion(selectVersion: Versions => String, release: Boolean): ReleaseStep = { st: State => | |
val vs = st.get(versions) | |
.getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?")) | |
val selected = selectVersion(vs) | |
val useGlobal = st.extract.get(releaseUseGlobalVersion) | |
st.log.info("Setting version to '%s'." format selected) | |
val versionStr = | |
if (release) { | |
(if (useGlobal) globalVersionString else versionString) format selected | |
} | |
else { | |
gitVersionString format Version(selected).map(_.withoutQualifier.string).getOrElse(versionFormatError) | |
} | |
writeVersion(st, versionStr) | |
reapply(Seq( | |
if (useGlobal) version in ThisBuild := selected | |
else version := selected, | |
git.baseVersion := Version(selected).map(_.withoutQualifier.string).getOrElse(versionFormatError) | |
), st) | |
} | |
lazy val setGitReleaseVersion: ReleaseStep = setVersion(_._1, true) | |
lazy val setGitNextVersion: ReleaseStep = setVersion(_._2, false) | |
releaseProcess := Seq[ReleaseStep]( | |
checkSnapshotDependencies, // : ReleaseStep | |
inquireVersions, // : ReleaseStep | |
runTest, // : ReleaseStep | |
setGitReleaseVersion, // : ReleaseStep | |
commitReleaseVersion, // : ReleaseStep, performs the initial git checks | |
tagRelease, // : ReleaseStep | |
publishArtifacts, // : ReleaseStep, checks whether `publishTo` is properly set up | |
setGitNextVersion, // : ReleaseStep | |
commitNextVersion, // : ReleaseStep | |
pushChanges // : ReleaseStep, also checks that an upstream branch is properly configured | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment