-
Notifications
You must be signed in to change notification settings - Fork 1
/
cancel.js
34 lines (28 loc) · 1020 Bytes
/
cancel.js
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
const core = require('@actions/core');
const github = require('@actions/github');
async function run() {
try {
const token = core.getInput('github-token');
const octokit = github.getOctokit(token);
const { context } = github;
const branch = context.ref.replace('refs/heads/', '');
// Get all workflow runs for the current branch that are pending
const { data: { workflow_runs: branch_runs } } = await octokit.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
status: 'queued'
});
console.log(branch_runs);
// Cancel them
for (const run of branch_runs) {
await octokit.rest.actions.cancelWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id
});
}
} catch (error) {
core.setFailed(`Action failed with error: ${error}`);
}
}
run();