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

fix cancelling jobs from different repos where two branches have the same name #105

Merged
merged 4 commits into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 10 additions & 1 deletion dist/index.js
Expand Up @@ -6122,6 +6122,14 @@ async function main() {
workflow_ids.push(String(current_run.workflow_id));
}
console.log(`Found workflow_id: ${JSON.stringify(workflow_ids)}`);
const trigger_repo_id = (function () {
if (payload.workflow_run) {
return payload.workflow_run.head_repository.id;
}
else {
return current_run.head_repository.id;
}
})();
await Promise.all(workflow_ids.map(async (workflow_id) => {
try {
const { data: { total_count, workflow_runs }, } = await octokit.actions.listWorkflowRuns({
Expand All @@ -6139,7 +6147,8 @@ async function main() {
.reduce((a, b) => Math.max(a, b), cancelBefore.getTime());
cancelBefore = new Date(n);
}
const runningWorkflows = workflow_runs.filter(run => run.id !== current_run.id &&
const runningWorkflows = workflow_runs.filter(run => run.head_repository.id === trigger_repo_id &&
run.id !== current_run.id &&
(ignore_sha || run.head_sha !== headSha) &&
run.status !== 'completed' &&
new Date(run.created_at) < cancelBefore);
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cancel-workflow-action",
"version": "0.9.0",
"version": "0.9.1",
styfle marked this conversation as resolved.
Show resolved Hide resolved
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Expand Up @@ -55,6 +55,13 @@ async function main() {
workflow_ids.push(String(current_run.workflow_id));
}
console.log(`Found workflow_id: ${JSON.stringify(workflow_ids)}`);
const trigger_repo_id = (function () {
if (payload.workflow_run) {
return payload.workflow_run.head_repository.id;
} else {
return current_run.head_repository.id;
}
})();
styfle marked this conversation as resolved.
Show resolved Hide resolved
await Promise.all(
workflow_ids.map(async workflow_id => {
try {
Expand All @@ -78,6 +85,7 @@ async function main() {
}
const runningWorkflows = workflow_runs.filter(
run =>
run.head_repository.id === trigger_repo_id &&
run.id !== current_run.id &&
(ignore_sha || run.head_sha !== headSha) &&
run.status !== 'completed' &&
Expand Down