gpt4 book ai didi

github-actions - 在 GitHub Actions 中,我可以返回一个值以供以后用作条件吗?

转载 作者:行者123 更新时间:2023-12-03 16:53:23 25 4
gpt4 key购买 nike

我正在将 GitHub Actions 设置为 one of my projects 的 CI ,并且整个构建过程基本上是一个PowerShell脚本,由环境变量驱动。

这既是为了最大限度地减少供应商锁定,并确保我可以使用几乎相同的过程在本地运行构建。

现在,我的构建脚本确定了一些内容并将其放入环境变量中 - 具体来说,我有一个 MH_IS_PROD_BUILD变量为 True 或 False,并确定我推送到哪个 nuget 包存储库。

但是,当运行 shell 的步骤完成时,环境变量将不复存在,因为进一步的步骤似乎是在新环境中运行的。

我想做的是这样的事情(缩写):

  steps:
- name: Run build script
id: pwshbuild
shell: pwsh
run: |
cd scripts
./build.ps1
# The above sets $Env:MH_IS_PROD_BUILD to either True or False
- name: Push Publish to GPR (Dev Package)
if: steps.pwshbuild.outputs.MH_IS_PROD_BUILD == 'False'
shell: pwsh
run: |
# omitted: determine $nupkgPath
nuget push $nupkgPath -Source "GPR" -SkipDuplicate
- name: Push Publish to Nuget.org (Release Package)
if: steps.pwshbuild.outputs.MH_IS_PROD_BUILD == 'True'
shell: pwsh
run: |
# omitted: determine $nupkgPath
nuget push $nupkgPath -Source "NugetOrg" -SkipDuplicate

看来 outputs是我需要的,但这似乎需要创建自定义操作?

以上当然不起作用(因此询问)。所以我想知道,最好的方法是什么?
  • 我可以从 PowerShell 设置步骤的输出吗? (首选)
  • 我是否必须创建一个自定义操作来封装我对 build.ps1 的调用,以便我可以通过输出返回内容?
  • 最佳答案

    我认为您可以通过将它们回显到控制台来设置 Powershell 的输出。 Powershell 有一个别名映射回显到 Write-Output .

    jobs:
    windows-test:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v1
    - name: Set outputs
    id: vars
    shell: pwsh
    run: echo "::set-output name=production::true"
    - name: Check outputs
    shell: pwsh
    run: echo ${{ steps.vars.outputs.production }}

    引用: https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-output-parameter-set-output

    关于github-actions - 在 GitHub Actions 中,我可以返回一个值以供以后用作条件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58675200/

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