尽管非零Python退出代码,但GitHub Action并没有显示错误

发布于 2025-02-11 20:29:52 字数 561 浏览 1 评论 0原文

我有一个Python脚本,该脚本在GitHub操作中以错误代码退出,但动作仍然显示出成功。我想在抛出非零退出代码时显示错误。脚本或工作流程中应该更改任何内容吗?

Python脚本:

import sys
import os
error_code = 256
print(f'error_code: {error_code}')
os._exit(error_code)
# have also tried sys.exit(error_code)

GitHub工作流程:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    
    - name: Setup Python
      uses: actions/setup-python@v3
      with:
        python-version: '3.10'

    - name: test
      run: python3 ./test_error_exit.py

I have a python script that exits with an error code inside a Github action, but the action still shows a success. I'd like for it to show an error when a non-zero exit code is thrown. Is there anything that should be changed in the script or workflow?

Python script:

import sys
import os
error_code = 256
print(f'error_code: {error_code}')
os._exit(error_code)
# have also tried sys.exit(error_code)

Github Workflow:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    
    - name: Setup Python
      uses: actions/setup-python@v3
      with:
        python-version: '3.10'

    - name: test
      run: python3 ./test_error_exit.py

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑依然 2025-02-18 20:29:52

在基于Linux的系统上,过程退出代码是返回的数字的8个最不重要的位。

这意味着返回0-255是有效的,此后它可以绕开。 (256变为0,257成为1等)

请用像5这样的出口代码重试。

import sys
sys.exit(5)

On linux based systems, process exit codes are the 8 least significant bits of the number returned.

This means returning 0-255 is valid, and after that it wraps around. (256 becoming 0, 257 becoming 1, etc.)

Please try again with an exit code like 5.

import sys
sys.exit(5)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文