Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow matching SHA to be canceled #50

Merged
merged 19 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
workflow_id:
description: 'Optional - A single Workflow ID or a comma separated list of IDs'
required: false
allow_matching_sha:
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
description: 'Allow matching SHA to be canceled. Useful when cancelling other workflows.'
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
required: false
default: false
access_token:
description: 'Your GitHub Access Token, defaults to: {{ github.token }}'
default: '${{ github.token }}'
Expand Down
9 changes: 7 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5859,6 +5859,7 @@ async function main() {
console.log({ eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID });
const token = core.getInput('access_token', { required: true });
const workflow_id = core.getInput('workflow_id', { required: false });
const allow_matching_sha = core.getInput('allow_matching_sha', { required: true }) === 'true';
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
console.log(`Found token: ${token ? 'yes' : 'no'}`);
const workflow_ids = [];
const octokit = github.getOctokit(token);
Expand All @@ -5885,9 +5886,13 @@ async function main() {
branch,
});
console.log(`Found ${data.total_count} runs total.`);
const runningWorkflows = data.workflow_runs.filter(run => run.head_branch === branch && run.head_sha !== headSha && run.status !== 'completed' &&
console.log(data.workflow_runs.map(run => `- ${run.html_url}`).join("\n"));
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
const runningWorkflows = data.workflow_runs.filter(run => run.head_branch === branch &&
(allow_matching_sha || run.head_sha !== headSha) &&
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
run.status !== 'completed' &&
new Date(run.created_at) < new Date(current_run.created_at));
console.log(`Found ${runningWorkflows.length} runs in progress.`);
console.log(`Found ${runningWorkflows.length} runs in to cancel.`);
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
console.log(runningWorkflows.map(run => `- ${run.html_url}`).join("\n"));
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
for (const { id, head_sha, status } of runningWorkflows) {
console.log('Cancelling another run: ', { id, head_sha, status });
const res = await octokit.actions.cancelWorkflowRun({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cancel-workflow-action",
"version": "0.6.0",
"version": "0.6.1",
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function main() {
console.log({ eventName, sha, headSha, branch, owner, repo, GITHUB_RUN_ID });
const token = core.getInput('access_token', { required: true });
const workflow_id = core.getInput('workflow_id', { required: false });
const allow_matching_sha = core.getInput('allow_matching_sha', { required: true }) === 'true';
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
console.log(`Found token: ${token ? 'yes' : 'no'}`);
const workflow_ids: string[] = [];
const octokit = github.getOctokit(token);
Expand Down Expand Up @@ -55,11 +56,17 @@ async function main() {
branch,
});
console.log(`Found ${data.total_count} runs total.`);
console.log(data.workflow_runs.map(run => `- ${run.html_url}`).join("\n"));

const runningWorkflows = data.workflow_runs.filter(
run => run.head_branch === branch && run.head_sha !== headSha && run.status !== 'completed' &&
new Date(run.created_at) < new Date(current_run.created_at)
run => run.head_branch === branch &&
(allow_matching_sha || run.head_sha !== headSha) &&
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
run.status !== 'completed' &&
new Date(run.created_at) < new Date(current_run.created_at)
);
console.log(`Found ${runningWorkflows.length} runs in progress.`);
console.log(`Found ${runningWorkflows.length} runs in to cancel.`);
ericmatte marked this conversation as resolved.
Show resolved Hide resolved
console.log(runningWorkflows.map(run => `- ${run.html_url}`).join("\n"));
ericmatte marked this conversation as resolved.
Show resolved Hide resolved

for (const {id, head_sha, status} of runningWorkflows) {
console.log('Cancelling another run: ', {id, head_sha, status});
const res = await octokit.actions.cancelWorkflowRun({
Expand Down