-
Notifications
You must be signed in to change notification settings - Fork 25
39 lines (39 loc) · 1.38 KB
/
e2e-cancel.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: E2E Cancel
on:
pull_request:
types:
- labeled
jobs:
cancel:
if: ${{ github.event.label.name == 'skip e2e' }}
runs-on: ubuntu-latest
steps:
# Avoid race conditions where the e2e job and this job both kick off at the same time.
- name: Pause
run: sleep 10
- name: Cancel
uses: actions/github-script@v7
with:
script: |
const { data: runs } = await github.request('GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs', {
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'e2e.yml',
head_sha: context.payload.pull_request.head.sha,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});
if (runs[0] && ['in_progress', 'pending', 'queued', 'requested', 'waiting'].includes(runs[0].status)) {
core.info(`Cancelling run ${runs[0].id}`);
await github.request('POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel', {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runs[0].id,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});
} else {
core.info('Nothing found to cancel');
}