From dfbe60528de9abd5047cec600e208906e4dabc4f Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Jan 2021 11:05:17 -0500 Subject: [PATCH] Improve logs (#53) --- README.md | 2 +- dist/index.js | 12 ++++++------ src/index.ts | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7bd49f0b..1c5a1a1d 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/dist/index.js b/dist/index.js index d68557d1..3f6721ee 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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, @@ -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() diff --git a/src/index.ts b/src/index.ts index 965d44fb..cab6909f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,7 +57,7 @@ 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 => @@ -65,11 +65,10 @@ async function main() { 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, @@ -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('') })); }