我已经在 GitHub actions 中设置了一个工作流程来运行我的测试并创建测试覆盖率的工件。我的 YAML 文件的精简版本如下所示:
name: Build
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Other steps here
- name: Build app
- name: Run tests
- name: Create artifact of test coverage
# Other steps here
问题是测试失败时不会创建工件。
我想通了if: always()
条件从docs https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#job-status-check-functions,但这也会导致此步骤在我的Build app
步骤失败。我不希望这种情况发生,因为在这种情况下没有什么可存档的。
如何仅在上一步已运行(成功或失败)的情况下才运行此步骤?
一个可能更好的选择是<step>.outcome
or <step>.conclusion
https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context https://docs.github.com/en/actions/learn-github-actions/contexts#steps-context
steps.<step id>.conclusion
。完成步骤后的结果出错时继续被申请;被应用。可能的值为success, failure, 取消, or skipped。当错误继续步骤失败时,结果是失败,但最终结论是成功。
steps.<step id>.outcome
之前完成的步骤的结果出错时继续被申请;被应用。可能的值为success, failure, 取消, or skipped。当错误继续步骤失败时,结果是失败,但最终结论是成功。
- name: Build app
id: build
run: |
<build command>
- name: Run tests
- name: Create artifact of test coverage
if: steps.build.outcome == 'success'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)