拆分sbt分阶段发布?

问题描述 投票:4回答:2

我有一个SBT项目和一个CD管道,我想要的是执行以下一系列步骤:

  1. 从git repo查看我的项目
  2. 标记提交
  3. 运行测试
  4. 打包我的应用

现在,此时我还不想发布任何内容,因为我会将二进制文件提升到另一个环境以运行端到端测试。只有当它们成功完成时,我才想推送git标签并将我的artefact上传到远程artefactory存储库。我真正想要实现的是,能够首先运行sbt prepereRelease,之后我将升级到我的测试环境,之后,如果一切正常,运行sbt doRelease。所以我想在build.sbt中使用类似的东西:

releaseProcess := Seq[ReleaseStep](
      checkSnapshotDependencies,
      inquireVersions,
      runClean,
      runTest,
      setReleaseVersion,
      commitReleaseVersion,
      tagRelease,
      setNextVersion,
      commitNextVersion
)

commands += Command.command("prepareRelease")((state:State) => {
  val newState = Command.process("release",state)
  println("Release called from prepareRelease...")
  newState
})

releaseProcess := Seq[ReleaseStep](
      publishArtifacts,
      setNextVersion,
      commitNextVersion,
      pushChanges
)

commands += Command.command("doRelease")((state:State) => {
  val newState = Command.process("release",state)
  println("Release called from doRelease...")
  newState
})

我几乎觉得我必须定义两个自定义命令,每个命令都必须使用不同的sbt-release设置从releaseProcess插件调用原始发布命令 - 这就是我不知道该怎么做的。不幸的是,上面的设置不起作用,因为releaseProcess设置累积了步骤,你仍然最终会立即执行所有步骤。

scala sbt sbt-release
2个回答
0
投票

您已将prepareReleasedoRelease定义为设置。这意味着设置的值仅在加载或重新加载构建时计算一次。此外,ReleaseStep类型仅描述要作为发布过程的一部分执行的函数,并且不会自行执行任何操作。

看起来你正在使用sbt-release插件。在文档之后,您将不得不使用自定义步骤重新定义releaseProcess密钥,并运行release命令来执行它们。


0
投票

我最终实现它的方法是创建两个自定义命令并将releaseProcess设置附加到state对象,然后将其传递到release插件:

// Defines the release process
releaseIgnoreUntrackedFiles := true

commands += Command.command("prepareRelease")((state: State) => {
  println("Preparing release...")
  val extracted = Project extract state
  val customState = extracted.append(Seq(releaseProcess := Seq[ReleaseStep](
    checkSnapshotDependencies,
    inquireVersions,
    runClean,
    setReleaseVersion,
    commitReleaseVersion,
    tagRelease,
    runTest
  )), state)
  val newState = Command.process("release with-defaults", customState)
  Command.process("dist", newState)
})

commands += Command.command("completeRelease")((state: State) => {
  println("Completing release...")
  val extracted = Project extract state
  val customState = extracted.append(Seq(releaseProcess := Seq[ReleaseStep](
    inquireVersions,
    setNextVersion,
    commitNextVersion,
    pushChanges
  )), state)
  val newState = Command.process("release with-defaults", customState)
  newState
})

所以我的管道做了类似于以下的事情:

  1. sbt prepareRelease
  2. 此时,我将二进制文件部署到我的TEST环境中
  3. 如果一切都运行良好,那么我做sbt completeRelease
  4. 最终curl我的拉链成为nexus
© www.soinside.com 2019 - 2024. All rights reserved.