@@ -10,8 +10,10 @@ import {
1010 restoreInputs ,
1111 getTemporaryDirectory ,
1212 printDebugLogs ,
13+ getWorkflowRunID ,
14+ getWorkflowRunAttempt ,
1315} from "./actions-util" ;
14- import { getGitHubVersion } from "./api-client" ;
16+ import { getApiClient , getGitHubVersion } from "./api-client" ;
1517import { CachingKind } from "./caching-utils" ;
1618import { getCodeQL } from "./codeql" ;
1719import { Config , getConfig } from "./config-utils" ;
@@ -42,6 +44,68 @@ interface InitPostStatusReport
4244 initActionPostHelper . JobStatusReport ,
4345 initActionPostHelper . DependencyCachingUsageReport { }
4446
47+ /**
48+ * TEMPORARY: Test function to check if the GitHub API can detect workflow cancellation.
49+ * This queries the Jobs API to see the current job's status and step conclusions.
50+ */
51+ async function testCancellationDetection ( ) : Promise < void > {
52+ const logger = getActionsLogger ( ) ;
53+ try {
54+ const apiClient = getApiClient ( ) ;
55+ const runId = getWorkflowRunID ( ) ;
56+ const attemptNumber = getWorkflowRunAttempt ( ) ;
57+ const jobName = process . env [ "GITHUB_JOB" ] || "" ;
58+ const repositoryNwo = getRepositoryNwo ( ) ;
59+
60+ logger . info (
61+ `[Cancellation Test] Querying jobs API for run ${ runId } , attempt ${ attemptNumber } , job "${ jobName } "` ,
62+ ) ;
63+
64+ const response = await apiClient . rest . actions . listJobsForWorkflowRunAttempt (
65+ {
66+ owner : repositoryNwo . owner ,
67+ repo : repositoryNwo . repo ,
68+ run_id : runId ,
69+ attempt_number : attemptNumber ,
70+ } ,
71+ ) ;
72+
73+ const currentJob = response . data . jobs . find ( ( j ) => j . name === jobName ) ;
74+
75+ if ( currentJob ) {
76+ logger . info (
77+ `[Cancellation Test] Current job status: ${ currentJob . status } , conclusion: ${ currentJob . conclusion } ` ,
78+ ) ;
79+
80+ // Log each step's status
81+ for ( const step of currentJob . steps || [ ] ) {
82+ logger . info (
83+ `[Cancellation Test] Step "${ step . name } ": status=${ step . status } , conclusion=${ step . conclusion } ` ,
84+ ) ;
85+ }
86+
87+ // Check if any step shows cancelled
88+ const hasCancelledStep = currentJob . steps ?. some (
89+ ( step ) => step . conclusion === "cancelled" ,
90+ ) ;
91+ logger . info (
92+ `[Cancellation Test] Has cancelled step: ${ hasCancelledStep } ` ,
93+ ) ;
94+ } else {
95+ logger . warning (
96+ `[Cancellation Test] Could not find job with name "${ jobName } " in API response` ,
97+ ) ;
98+ logger . info (
99+ `[Cancellation Test] Available jobs: ${ response . data . jobs . map ( ( j ) => j . name ) . join ( ", " ) } ` ,
100+ ) ;
101+ }
102+ } catch ( error ) {
103+ logger . warning (
104+ `[Cancellation Test] Failed to query API: ${ error instanceof Error ? error . message : String ( error ) } ` ,
105+ ) ;
106+ }
107+ }
108+
45109async function run ( startedAt : Date ) {
46110 // To capture errors appropriately, keep as much code within the try-catch as
47111 // possible, and only use safe functions outside.
@@ -53,6 +117,9 @@ async function run(startedAt: Date) {
53117 | undefined ;
54118 let dependencyCachingUsage : DependencyCachingUsageReport | undefined ;
55119 try {
120+ // TEMPORARY: Test cancellation detection via API
121+ await testCancellationDetection ( ) ;
122+
56123 // Restore inputs from `init` Action.
57124 restoreInputs ( ) ;
58125
0 commit comments