4

I'm trying to release my sbt project using sbt-release plugin. When I execute 'sbt release ' task on the develop brunch, it creates a new tag based on this branch, but doesn't merge changes from the current develop branch to the master. Is it possible to merge all changes made in develop branch to the master while releasing?

I need something like this:

  1. Change the project version to release version and push those changes to the remote develop branch.
  2. Merge the latest develop commit to the master branch and tag it.
  3. Change the version number to the next snapshot and push those changes back to the remote develop.

So how can I achieve this behaviour?

aenw
  • 841
  • 9
  • 18
Mike
  • 209
  • 1
  • 11

2 Answers2

4

You can do it by changing the release process with your own custom steps. Basically I just copied the steps from the sbt-release code, and added some of mine own

lazy val deploySettings: Seq[Def.Setting[_]] = {
  import ReleaseTransformations._
  import ReleasePlugin.autoImport._
  import sbtrelease.{Git, Utilities, ExtraReleaseCommands}
  import Utilities._
  val deployBranch = "master"
  def merge: (State) => State = { st: State =>
    val git = st.extract.get(releaseVcs).get.asInstanceOf[Git]
    val curBranch = (git.cmd("rev-parse", "--abbrev-ref", "HEAD") !!).trim
    st.log.info(s"####### current branch: $curBranch")
    git.cmd("checkout", deployBranch) ! st.log
    st.log.info(s"####### pull $deployBranch")
    git.cmd("pull") ! st.log
    st.log.info(s"####### merge")
    git.cmd("merge", curBranch, "--no-ff", "--no-edit") ! st.log
    st.log.info(s"####### push")
    git.cmd("push", "origin", s"$deployBranch:$deployBranch") ! st.log
    st.log.info(s"####### checkout $curBranch")
    git.cmd("checkout", curBranch) ! st.log
    st
  }
  lazy val mergeReleaseVersionAction = { st: State =>
    val newState = merge(st)
    newState
  }
  val mergeReleaseVersion = ReleaseStep(mergeReleaseVersionAction)
  publishingSettings ++
    Seq(
      releaseProcess := Seq[ReleaseStep](
        checkSnapshotDependencies,
        inquireVersions,
        runClean,
        runTest,
        setReleaseVersion,
        commitReleaseVersion,
        pushChanges,                //to make sure develop branch is pulled
        mergeReleaseVersion,        //will merge into master and push
        tagRelease,
        setNextVersion,
        commitNextVersion,
        pushChanges
      )
    )
}

it assumes that you are using git

not very pretty, but it works.

lev
  • 3,986
  • 4
  • 33
  • 46
1

lev's advice is more or less correct though when using sbt 1.2.8 I found the API has changed and things didn't work as expected. I had to make everything top level removing the deploySettings enclosing block and also had to make a change to the release steps assignment. Here's my version:

import ReleaseTransformations._
import ReleasePlugin.autoImport._
import sbtrelease.{Git, Utilities}
import Utilities._
val deployBranch = "master"
def merge: (State) => State = { st: State =>
  val git = st.extract.get(releaseVcs).get.asInstanceOf[Git]
  val curBranch = (git.cmd("rev-parse", "--abbrev-ref", "HEAD") !!).trim
  st.log.info(s"####### current branch: $curBranch")
  git.cmd("checkout", deployBranch) ! st.log
  st.log.info(s"####### pull $deployBranch")
  git.cmd("pull") ! st.log
  st.log.info(s"####### merge")
  git.cmd("merge", curBranch, "--no-ff", "--no-edit") ! st.log
  st.log.info(s"####### push")
  git.cmd("push", "origin", s"$deployBranch:$deployBranch") ! st.log
  st.log.info(s"####### checkout $curBranch")
  git.cmd("checkout", curBranch) ! st.log
  st
}

lazy val mergeReleaseVersionAction = { st: State =>
  val newState = merge(st)
  newState
}

val mergeReleaseVersion = ReleaseStep(mergeReleaseVersionAction)

releaseProcess := Seq[ReleaseStep](
  checkSnapshotDependencies,
  inquireVersions,
  runClean,
  runTest,
  setReleaseVersion,
  commitReleaseVersion,
  pushChanges,                //to make sure develop branch is pulled
  tagRelease,
  mergeReleaseVersion,        //will merge into master and push
  setNextVersion,
  commitNextVersion,
  pushChanges
)

HTH!

James K
  • 306
  • 1
  • 7