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

Improve logs #53

Merged
merged 4 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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