Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
fix: only cancel branch, and check GITHUB_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarjit committed Jul 9, 2024
1 parent d7e5af4 commit 4991065
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ const github = require('@actions/github');

async function run() {
try {
const token = core.getInput('github-token');
const token = core.getInput('GITHUB_TOKEN');
if (!token) {
core.error('GITHUB_TOKEN is required');
}

const octokit = github.getOctokit(token);
const { context } = github;
const branch = context.ref.replace('refs/heads/', '');
Expand All @@ -15,10 +19,16 @@ async function run() {
status: 'queued'
});

console.log(branch_runs);
core.debug(branch_runs);

// Cancel them
for (const run of branch_runs) {
if (run.head_branch !== branch) {
core.info(`Skipping run ${run.id} as it is not for the current branch`);
continue;
}
core.info(`Cancelling run ${run.id}`);

await octokit.rest.actions.cancelWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down

0 comments on commit 4991065

Please sign in to comment.