3636 with :
3737 github-token : ${{ secrets.GITHUB_TOKEN }}
3838 script : |
39- console.log("Starting workflow cancellation");
40- console.log("Current run:", JSON.stringify(context));
41- console.log("Current runId:", context.runId);
42- console.log("Current commit SHA:", context.sha);
43- console.log("Current branch:", context.payload.pull_request?.head.ref);
44-
4539 // Get all workflow runs
4640 const runs = await github.rest.actions.listWorkflowRunsForRepo({
4741 owner: context.repo.owner,
@@ -50,39 +44,11 @@ jobs:
5044 branch: context.payload.pull_request?.head.ref,
5145 });
5246
53- console.log("Total in-progress runs found:", runs.data.workflow_runs.length);
54-
55- // Log all found runs
56- runs.data.workflow_runs.forEach(run => {
57- console.log(`Run: ${JSON.stringify(run)}, Run ID: ${run.id}, Name: ${run.name}, SHA: ${run.head_sha}`);
58- });
59-
60- runs.data.workflow_runs.forEach(run => {
61- if (run.head_sha === context.sha) {
62- console.log(`Found matching run 1: ${run.id} (${run.name}) for SHA: ${run.head_sha}`);
63- } else if (run.head_sha == context.sha) {
64- console.log(`Found matching run 2: ${run.id} (${run.name}) for SHA: ${run.head_sha}`);
65- } else {
66- console.log(`No match for run: ${run.id} (${run.name}) for SHA: ${run.head_sha}`);
67- }
68- });
69-
70- // Filter runs by the same commit SHA and exclude the current run
71- const relatedRuns = runs.data.workflow_runs.filter(run =>
72- run.head_sha == context.sha &&
73- (run.name == 'Integration Tests' || run.name == 'Compose Tests')
74- );
75-
76- console.log("Matching runs to cancel:", relatedRuns.length);
77-
78- // Cancel each related run (not by relatedruns)
7947 for (const run of runs.data.workflow_runs) {
8048 if (run.id === context.runId) {
81- console.log(`Skipping current run ${run.id} (${run.name})`);
8249 continue;
8350 }
8451 if (run.name !== 'Integration Tests' && run.name !== 'Compose Tests') {
85- console.log(`Skipping unrelated run ${run.id} (${run.name})`);
8652 continue;
8753 }
8854 console.log(`Attempting to cancel workflow run ${run.id} (${run.name})`);
0 commit comments