Skip to content

Commit

Permalink
Improve logs (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jan 12, 2021
1 parent 277e407 commit dfbe605
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This includes runs with a [status](https://docs.github.com/en/rest/reference/che

## How does it work?

When you `git push`, this GitHub Action will capture the current Branch and SHA. It will query GitHub's API to find previous workflow runs that match the Branch but do not match the SHA. These in-progress runs will be cancelled leaving only the latest run.
When you `git push`, this GitHub Action will capture the current Branch and SHA. It will query GitHub's API to find previous workflow runs that match the Branch but do not match the SHA. These in-progress runs will be canceled leaving only the latest run.

Read more about the [Workflow Runs API](https://docs.github.com/en/rest/reference/actions#workflow-runs).

Expand Down
12 changes: 6 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5886,15 +5886,14 @@ async function main() {
branch,
});
const branchWorkflows = data.workflow_runs.filter(run => run.head_branch === branch);
console.log(`Found ${branchWorkflows.length} runs total for branch ${branch}.`);
console.log(`Found ${branchWorkflows.length} runs for workflow ${workflow_id} on branch ${branch}`);
console.log(branchWorkflows.map(run => `- ${run.html_url}`).join('\n'));
const runningWorkflows = branchWorkflows.filter(run => (ignore_sha || run.head_sha !== headSha) &&
run.status !== 'completed' &&
new Date(run.created_at) < new Date(current_run.created_at));
console.log(`Found ${runningWorkflows.length} runs to cancel.`);
console.log(runningWorkflows.map(run => `- ${run.html_url}`).join('\n'));
for (const { id, head_sha, status } of runningWorkflows) {
console.log('Cancelling another run: ', { id, head_sha, status });
console.log(`with ${runningWorkflows.length} runs to cancel.`);
for (const { id, head_sha, status, html_url } of runningWorkflows) {
console.log('Canceling run: ', { id, head_sha, status, html_url });
const res = await octokit.actions.cancelWorkflowRun({
owner,
repo,
Expand All @@ -5905,8 +5904,9 @@ async function main() {
}
catch (e) {
const msg = e.message || e;
console.log(`Error while cancelling workflow_id ${workflow_id}: ${msg}`);
console.log(`Error while canceling workflow_id ${workflow_id}: ${msg}`);
}
console.log('');
}));
}
main()
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ async function main() {
});

const branchWorkflows = data.workflow_runs.filter(run => run.head_branch === branch);
console.log(`Found ${branchWorkflows.length} runs total for branch ${branch}.`);
console.log(`Found ${branchWorkflows.length} runs for workflow ${workflow_id} on branch ${branch}`);
console.log(branchWorkflows.map(run => `- ${run.html_url}`).join('\n'));

const runningWorkflows = branchWorkflows.filter(run =>
(ignore_sha || run.head_sha !== headSha) &&
run.status !== 'completed' &&
new Date(run.created_at) < new Date(current_run.created_at)
);
console.log(`Found ${runningWorkflows.length} runs to cancel.`);
console.log(runningWorkflows.map(run => `- ${run.html_url}`).join('\n'));
console.log(`with ${runningWorkflows.length} runs to cancel.`);

for (const {id, head_sha, status} of runningWorkflows) {
console.log('Cancelling another run: ', {id, head_sha, status});
for (const {id, head_sha, status, html_url} of runningWorkflows) {
console.log('Canceling run: ', {id, head_sha, status, html_url});
const res = await octokit.actions.cancelWorkflowRun({
owner,
repo,
Expand All @@ -79,8 +78,9 @@ async function main() {
}
} catch (e) {
const msg = e.message || e;
console.log(`Error while cancelling workflow_id ${workflow_id}: ${msg}`);
console.log(`Error while canceling workflow_id ${workflow_id}: ${msg}`);
}
console.log('')
}));
}

Expand Down

0 comments on commit dfbe605

Please sign in to comment.