与SBT release-plugin合并为master



我正在尝试使用sbt-release插件发布我的sbt项目。当我在开发分支上执行"sbt release"任务时,它会基于这个分支创建一个新的标签,但是不会将当前开发分支的更改合并到主分支中。是否有可能在发布时将开发分支中的所有更改合并到主分支中?

我需要这样的东西:

  1. 将项目版本更改为发布版本,并将这些更改推送到远程开发分支
  2. 将最新的开发提交合并到主分支并标记。
  3. 更改下一个快照的版本号并将这些更改推回远程开发。

那么我怎样才能实现这个行为呢?

您可以通过使用您自己的自定义步骤更改发布过程来做到这一点。基本上,我只是复制了sbt-release代码的步骤,并添加了一些我自己的

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
      )
    )
}

假设你正在使用git

lev的建议或多或少是正确的,尽管当使用sbt 1.2.8时,我发现API已经改变,事情没有像预期的那样工作。我不得不把所有的东西都放在顶层,删除deploySettings封闭块,还必须对释放步骤分配进行更改。这是我的版本:

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 !

相关内容

  • 没有找到相关文章

最新更新