在 github-actions 中推送新提交(更新当前)时如何取消 PR 中的先前运行
问题描述:
当我将提交推送到 PR 时,我的测试会为此提交触发.之后,如果我向这个 PR 推送额外的提交,Github Actions 中的测试会在两个提交上运行.
When I push my commits to a PR my tests are triggered for this commit. After that, if I push additional commits to this PR, tests in Github Actions runs on both commits.
我需要取消之前的运行并仅在最近推送的提交上运行它们.
I need to cancel the previous run and run them only on the most recent pushed commit.
如何配置我的 yaml 文件来实现这一点?
How can I configure my yaml file to achieve that?
答
更新
这不再有效,GitHub Actions 从那以后改进了这种体验.首先查看替代答案.
就像我们之前说的有一个应用程序可以解决这个问题!",现在是有一个操作可以解决这个问题!":
Like we had "There's an app for that!", now it's "There's an Action for that!":
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
#- name: Run Tests
# uses: actions/setup-node@v1
# run: node test.js
# ... etc