我试图使用sbt-release插件发布我的sbt项目。 当我执行'sbt release'开发早午餐的任务,它创建一个基于此分支的新标签,但不会将当前开发分支的更改合并到主分支。 是否可以在发布时将开发分支中的所有更改合并到主服务器?
我需要这样的东西:
那我怎么能实现这种行为?
答案 0 :(得分:4)
您可以使用自己的自定义步骤更改发布流程。
基本上我只是复制了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
不是很漂亮,但它确实有效。
答案 1 :(得分:0)
lev的建议或多或少是正确的,我发现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!