【问题标题】:How it is possible to avoid a push in Github when the workflow tests fails?当工作流测试失败时,如何避免在 Github 中推送?
【发布时间】:2020-08-11 07:39:38
【问题描述】:

我创建了工作流以在提交之前测试我的 Python 应用程序。问题是,如果测试失败,无论如何都会推送提交。如果测试不成功,我如何添加条件来避免推送?

工作流文件 .yml 的结构如下。

`名称:Python 应用程序 在: 推: 分支:[主] 拉取请求: 分支:[主]

工作: 构建:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
  uses: actions/setup-python@v1
  with:
    python-version: 3.8
- name: Install dependencies
  run: |
    python -m pip install --upgrade pip
    pip install -r requirements.txt
- name: Lint with flake8
  run: |
    pip install flake8
    # stop the build if there are Python syntax errors or undefined names
    flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
    # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
    flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
  run: |
    pip install pytest
    pytest`

Test fail screenshot

【问题讨论】:

  • 该工作流(any 工作流,就此而言)只能get 被推送的代码。如果您想在 推送之前进行测试,则需要在 本地 进行。你可以研究 git hooks 来自动化它。

标签: python testing github github-actions workload


【解决方案1】:

您实际上无法通过 CI 系统阻止推送,原因有几个。

首先,您的 CI 系统需要能够访问要推送的数据,这意味着它必须存在于某个存储库中,以便可以获取它。其次,CI 系统可能需要很长时间才能运行,没有人愿意在 CI 系统运行时等待他们的推动成功或失败。如果您在工作日结束前推送怎么办?

您通常执行此操作的方式是推送到分支,让 CI 系统运行,然后将其合并。如果您与多人一起工作,那么使用拉取请求并将您的 CI 设置为在打开或更新一个 CI 时运行是正确的举措。否则,您可以将工作流设置为在所有分支上操作(像这样),然后在分支通过时合并:

on: push

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-05
    • 2023-01-03
    • 2021-11-14
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    相关资源
    最近更新 更多