sbt-release
sbt-release copied to clipboard
Split sbt release in stages?
I have an SBT project and a CD pipeline and what I want is to execute the following sequence of events:
- Checkout my project from the git repo
- Tag the commit
- Run the tests
- Package my app
- Now at this point I don't want to release anything yet as I will promote the binaries to another environment to run the end-to-end tests. Only if they complete successfully would I want to push the git tags and upload my artefact to the remote artefactory repository. So I want something similar to this in my build.sbt but I'm not quite sure how exactly to extend the existing release process:
lazy val prepareRelease = settingKey[Seq[ReleaseStep]]("Prepare the release")
prepareRelease := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease
)
lazy val doRelease = settingKey[Seq[ReleaseStep]]("Perform the release")
doRelease := Seq[ReleaseStep](
publishArtifacts,
setNextVersion,
commitNextVersion,
pushChanges
)
What I want to achieve really is to be able to first run sbt prepereRelease after which I will promote to my TEST environment and later, if everything goes ok, to run sbt doRelease.
Is there a way to achieve this atm?
What I ended up doing it is creating two custom commands and appending the releaseProcess setting to the state object which I then pass onto the release plugin. Not sure if there's a better way of doing the same thing:
// Defines the release process
releaseIgnoreUntrackedFiles := true
commands += Command.command("prepareRelease")((state: State) => {
println("Preparing release...")
val extracted = Project extract state
var st = extracted.append(Seq(releaseProcess := Seq[ReleaseStep](
runClean,
checkSnapshotDependencies,
inquireVersions,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
runTest,
releaseStepTask(coverageReport),
releaseStepTask(dist)
)), state)
Command.process("release with-defaults", st)
})
commands += Command.command("completeRelease")((state: State) => {
println("Completing release...")
val extracted = Project extract state
val customState = extracted.append(Seq(releaseProcess := Seq[ReleaseStep](
inquireVersions,
setNextVersion,
commitNextVersion,
pushChanges
)), state)
val newState = Command.process("release with-defaults", customState)
newState
})