我正在尝试使用 sbt-release 插件发布我的 sbt 项目。当我在开发早午餐上执行“sbt release”任务时,它会基于此分支创建一个新标签,但不会将当前开发分支的更改合并到主分支。是否可以在发布时将开发分支中所做的所有更改合并到主分支?
我需要这样的东西:
- 将项目版本更改为发布版本并将这些更改推送到远程开发分支。
- 将最新的开发提交合并到主分支并标记它。
- 将版本号更改为下一个快照并将这些更改推送回远程开发。
那么我怎样才能实现这种行为呢?
我正在尝试使用 sbt-release 插件发布我的 sbt 项目。当我在开发早午餐上执行“sbt release”任务时,它会基于此分支创建一个新标签,但不会将当前开发分支的更改合并到主分支。是否可以在发布时将开发分支中所做的所有更改合并到主分支?
我需要这样的东西:
那么我怎样才能实现这种行为呢?
您可以通过使用自己的自定义步骤更改发布过程来做到这一点。基本上我只是复制了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
)
!