python - 当工作流测试失败时,如何避免在 Github 中推送?
问题描述
我创建了工作流来在提交之前测试我的 Python 应用程序。问题是,如果测试失败,无论如何都会推送提交。如果测试不成功,我如何添加条件来避免推送?
工作流文件 .yml 的结构如下。
`名称:Python应用程序:推送:分支:[master] pull_request:分支:[master]
工作: 建造:
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`
解决方案
出于几个原因,您实际上无法使用 CI 系统阻止推送。
首先,您的 CI 系统需要能够访问要推送的数据,这意味着它必须存在于某个存储库中,以便可以获取它。其次,CI 系统可能需要很长时间才能运行,没有人愿意在 CI 系统运行时等待他们的推送成功或失败。如果你在工作日结束前推送怎么办?
你通常这样做的方式是推送到一个分支,让 CI 系统运行,然后合并它。如果您与多人一起工作,那么使用拉取请求并将您的 CI 设置为在打开或更新一个 CI 时运行是正确的举措。否则,您可以将工作流设置为在所有分支上操作(像这样),然后在分支通过时合并:
on: push
推荐阅读
- python - 无法将熊猫列转换为字符串
- laravel - 在 Eloquent 中默认忽略具有特定值的列
- java - Java - 修改复制的数组也会影响原始数组
- java - 如何在java中垂直循环遍历二维数组
- python-3.x - Folium choropleth 根本不给邮政编码区域着色
- java - 特殊字符检查,如果语句不起作用。爪哇
- django - Django 检索 CRSF 令牌
- swift - 更新 ObservableObject 值会关闭视图
- google-api - google 的 DCM api 中的什么会给我返回字段的数据类型?
- javascript - React-Bootstrap 不适用于组件