Skip to content

Commit 625ae85

Browse files
committed
Pass check run ID via input
1 parent a753f07 commit 625ae85

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

init/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ inputs:
159159
description: >-
160160
Explicitly enable or disable caching of project build dependencies.
161161
required: false
162+
check-run-id:
163+
description: >-
164+
TEMPORARY: The check run ID of the current job (from job.check_run_id context).
165+
Used for testing cancellation detection via the API.
166+
required: false
167+
default: ${{ job.check_run_id }}
162168
outputs:
163169
codeql-path:
164170
description: The path of the CodeQL binary used for analysis

lib/init-action-post.js

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init-action-post.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ async function testCancellationDetection(): Promise<void> {
5454
const apiClient = getApiClient();
5555
const runId = getWorkflowRunID();
5656
const attemptNumber = getWorkflowRunAttempt();
57-
const jobName = process.env["GITHUB_JOB"] || "";
57+
const checkRunIdInput = process.env["INPUT_CHECK-RUN-ID"] || "";
5858
const repositoryNwo = getRepositoryNwo();
5959

60+
if (!checkRunIdInput) {
61+
logger.warning(
62+
"[Cancellation Test] check-run-id input not provided, skipping",
63+
);
64+
return;
65+
}
66+
67+
const checkRunId = parseInt(checkRunIdInput, 10);
6068
logger.info(
61-
`[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, job "${jobName}"`,
69+
`[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, check_run_id ${checkRunId}`,
6270
);
6371

6472
const response = await apiClient.rest.actions.listJobsForWorkflowRunAttempt(
@@ -70,33 +78,35 @@ async function testCancellationDetection(): Promise<void> {
7078
},
7179
);
7280

73-
const currentJob = response.data.jobs.find((j) => j.name === jobName);
81+
const jobs = response.data.jobs;
82+
const currentJob = jobs.find((j) => j.id === checkRunId);
7483

7584
if (currentJob) {
7685
logger.info(
7786
`[Cancellation Test] Current job status: ${currentJob.status}, conclusion: ${currentJob.conclusion}`,
7887
);
7988

8089
// Log each step's status
81-
for (const step of currentJob.steps || []) {
90+
const steps = currentJob.steps || [];
91+
for (const step of steps) {
8292
logger.info(
8393
`[Cancellation Test] Step "${step.name}": status=${step.status}, conclusion=${step.conclusion}`,
8494
);
8595
}
8696

8797
// Check if any step shows cancelled
88-
const hasCancelledStep = currentJob.steps?.some(
98+
const hasCancelledStep = steps.some(
8999
(step) => step.conclusion === "cancelled",
90100
);
91101
logger.info(
92102
`[Cancellation Test] Has cancelled step: ${hasCancelledStep}`,
93103
);
94104
} else {
95105
logger.warning(
96-
`[Cancellation Test] Could not find job with name "${jobName}" in API response`,
106+
`[Cancellation Test] Could not find job with check_run_id ${checkRunId} in API response`,
97107
);
98108
logger.info(
99-
`[Cancellation Test] Available jobs: ${response.data.jobs.map((j) => j.name).join(", ")}`,
109+
`[Cancellation Test] Available jobs: ${jobs.map((j) => `${j.id} (${j.name})`).join(", ")}`,
100110
);
101111
}
102112
} catch (error) {

0 commit comments

Comments
 (0)