如果 mypy 返回错误,如何使 Python CI GitHub Action 作业失败?

问题描述

我的 GitHub 操作已设置为 width: calc(#{$i/$columns}*100% - #{$padding-mini}); 和我的 windows-latest 命令。

工作: 构建:

mypy

我在 GitHub 控制台中出现操作运行错误,但这不会导致作业失败。如何使作业因 runs-on: windows-latest steps: - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} - name: Set up Python 3.x uses: actions/setup-python@v2 with: python-version: '3.8' - name: Install dependencies run: | python -m pip install --upgrade pip pip install mypy pip install -r requirements.txt - name: Lint with mypy run: | Get-ChildItem . -Filter "*.py" -Recurse | foreach {mypy $_.FullName ` --show-error-codes ` --raise-exceptions } 错误而失败?

mypy 文档没有提及任何有关指定错误失败或指定错误返回代码内容

解决方法

如果您想使作业或步骤失败,则需要返回非 0 退出代码。 请参阅此处:https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/setting-exit-codes-for-actions

我不熟悉 mypy 在您的示例中正在做什么,但是如果您希望它基于某些输出使该步骤失败,那么您可能应该将输出保存到一个变量中,检查它是否符合您的期望“失败”然后“退出 1”,以便返回到 github 操作,该操作随后将失败该步骤。