Master merge with sbt release plugin

I am trying to release my sbt project using the sbt-release plugin. When I run the "sbt release" task on the development branch, it creates a new tag based on this branch, but does not merge the changes from the current development branch to the leading one. Is it possible to merge all changes made to the development branch into a wizard upon release?

I need something like this:

  • Change the project version to release the version and push these changes to the remote deployment branch.
  • Combine the latest version of commit with the leading branch and tag it.
  • Change the version number to the next snapshot and push these changes back to the remote computer.

So how can I achieve this behavior?

+4
source share
2 answers

You can do this by modifying the release process using your own custom steps. I basically just copied the steps from the code sbt-releaseand added some of my 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
      )
    )
}

assumed that you are using git

not very pretty, but it works.

+4
source

The lev tip is more or less correct, although when using sbt 1.2.8 I found that the API has changed and everything is not working as expected. I had to do everything at the highest level, removing the deploySettingsinclusion block and also had to make changes in the purpose of the release steps. Here is 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
)

NTN!

0
source

Source: https://habr.com/ru/post/1607947/


All Articles