diff --git a/init/action.yml b/init/action.yml index 57d5a9940..c4c9c0275 100644 --- a/init/action.yml +++ b/init/action.yml @@ -159,6 +159,12 @@ inputs: description: >- Explicitly enable or disable caching of project build dependencies. required: false + check-run-id: + description: >- + TEMPORARY: The check run ID of the current job (from job.check_run_id context). + Used for testing cancellation detection via the API. + required: false + default: ${{ job.check_run_id }} outputs: codeql-path: description: The path of the CodeQL binary used for analysis diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 86728f8a8..f06bc514a 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -132913,10 +132913,17 @@ async function testCancellationDetection() { const apiClient = getApiClient(); const runId = getWorkflowRunID(); const attemptNumber = getWorkflowRunAttempt(); - const jobName = process.env["GITHUB_JOB"] || ""; + const checkRunIdInput = process.env["INPUT_CHECK-RUN-ID"] || ""; const repositoryNwo = getRepositoryNwo(); + if (!checkRunIdInput) { + logger.warning( + "[Cancellation Test] check-run-id input not provided, skipping" + ); + return; + } + const checkRunId = parseInt(checkRunIdInput, 10); logger.info( - `[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, job "${jobName}"` + `[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, check_run_id ${checkRunId}` ); const response = await apiClient.rest.actions.listJobsForWorkflowRunAttempt( { @@ -132926,17 +132933,19 @@ async function testCancellationDetection() { attempt_number: attemptNumber } ); - const currentJob = response.data.jobs.find((j) => j.name === jobName); + const jobs = response.data.jobs; + const currentJob = jobs.find((j) => j.id === checkRunId); if (currentJob) { logger.info( `[Cancellation Test] Current job status: ${currentJob.status}, conclusion: ${currentJob.conclusion}` ); - for (const step of currentJob.steps || []) { + const steps = currentJob.steps || []; + for (const step of steps) { logger.info( `[Cancellation Test] Step "${step.name}": status=${step.status}, conclusion=${step.conclusion}` ); } - const hasCancelledStep = currentJob.steps?.some( + const hasCancelledStep = steps.some( (step) => step.conclusion === "cancelled" ); logger.info( @@ -132944,10 +132953,10 @@ async function testCancellationDetection() { ); } else { logger.warning( - `[Cancellation Test] Could not find job with name "${jobName}" in API response` + `[Cancellation Test] Could not find job with check_run_id ${checkRunId} in API response` ); logger.info( - `[Cancellation Test] Available jobs: ${response.data.jobs.map((j) => j.name).join(", ")}` + `[Cancellation Test] Available jobs: ${jobs.map((j) => `${j.id} (${j.name})`).join(", ")}` ); } } catch (error3) { diff --git a/src/init-action-post.ts b/src/init-action-post.ts index a6dca82e7..d6b81aef3 100644 --- a/src/init-action-post.ts +++ b/src/init-action-post.ts @@ -54,11 +54,19 @@ async function testCancellationDetection(): Promise { const apiClient = getApiClient(); const runId = getWorkflowRunID(); const attemptNumber = getWorkflowRunAttempt(); - const jobName = process.env["GITHUB_JOB"] || ""; + const checkRunIdInput = process.env["INPUT_CHECK-RUN-ID"] || ""; const repositoryNwo = getRepositoryNwo(); + if (!checkRunIdInput) { + logger.warning( + "[Cancellation Test] check-run-id input not provided, skipping", + ); + return; + } + + const checkRunId = parseInt(checkRunIdInput, 10); logger.info( - `[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, job "${jobName}"`, + `[Cancellation Test] Querying jobs API for run ${runId}, attempt ${attemptNumber}, check_run_id ${checkRunId}`, ); const response = await apiClient.rest.actions.listJobsForWorkflowRunAttempt( @@ -70,7 +78,8 @@ async function testCancellationDetection(): Promise { }, ); - const currentJob = response.data.jobs.find((j) => j.name === jobName); + const jobs = response.data.jobs; + const currentJob = jobs.find((j) => j.id === checkRunId); if (currentJob) { logger.info( @@ -78,14 +87,15 @@ async function testCancellationDetection(): Promise { ); // Log each step's status - for (const step of currentJob.steps || []) { + const steps = currentJob.steps || []; + for (const step of steps) { logger.info( `[Cancellation Test] Step "${step.name}": status=${step.status}, conclusion=${step.conclusion}`, ); } // Check if any step shows cancelled - const hasCancelledStep = currentJob.steps?.some( + const hasCancelledStep = steps.some( (step) => step.conclusion === "cancelled", ); logger.info( @@ -93,10 +103,10 @@ async function testCancellationDetection(): Promise { ); } else { logger.warning( - `[Cancellation Test] Could not find job with name "${jobName}" in API response`, + `[Cancellation Test] Could not find job with check_run_id ${checkRunId} in API response`, ); logger.info( - `[Cancellation Test] Available jobs: ${response.data.jobs.map((j) => j.name).join(", ")}`, + `[Cancellation Test] Available jobs: ${jobs.map((j) => `${j.id} (${j.name})`).join(", ")}`, ); } } catch (error) {