gpt4 book ai didi

scala - 分阶段拆分 sbt 发布?

转载 作者:行者123 更新时间:2023-12-04 16:00:34 26 4
gpt4 key购买 nike

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

  • 从 git 存储库中 checkout 我的项目
  • 标记提交
  • 运行测试
  • 打包我的应用

  • 现在,我不想发布任何内容,因为我会将二进制文件提升到另一个环境以运行端到端测试。只有当它们成功完成时,我才会想要推送 git 标签并将我的工件上传到远程 artefactory 存储库。我真正想要实现的,是能够第一次运行 sbt prepereRelease之后我将升级到我的 TEST 环境,然后,如果一切顺利,运行 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 调用原始的 release 命令。具有不同的插件 releaseProcess设置 - 这就是我不知道该怎么做的一点。不幸的是,上面的设置不能像 releaseProcess 那样工作。设置累积步骤,您仍然会一次执行所有步骤。

    最佳答案

    我最终实现它的方式是创建两个自定义命令并附加 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
    })

    所以我的管道做了类似于以下的事情:
  • sbt prepareRelease
  • 此时,我将二进制文件部署到我的 TEST 环境
  • 如果一切顺利,那么我会做 sbt completeRelease
  • 最终 curl我的 zip 到 nexus
  • 关于scala - 分阶段拆分 sbt 发布?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49100128/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com