Mike Mike - 3 months ago 14
Git Question

merge to master with sbt release-plugin

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?

lev lev
Answer

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.