@@ -16,7 +16,10 @@ import {
1616 persistInputs ,
1717} from "./actions-util" ;
1818import { AnalysisKind , getAnalysisKinds } from "./analyses" ;
19- import { getAnalysisSkipReason } from "./analysis-skip" ;
19+ import {
20+ getAnalysisSkipReason ,
21+ getDraftAnalysisSkipReason ,
22+ } from "./analysis-skip" ;
2023import { getGitHubVersion , GitHubApiCombinedDetails } from "./api-client" ;
2124import {
2225 getDependencyCachingEnabled ,
@@ -201,6 +204,17 @@ async function sendCompletedStatusReport(
201204 }
202205}
203206
207+ function markAnalysisSkipped ( reason : string , logger : Logger ) {
208+ logger . info (
209+ `Skipping CodeQL before tool download and database initialization: ${ reason } .` ,
210+ ) ;
211+ core . exportVariable ( EnvVar . ANALYSIS_SKIP_REASON , reason ) ;
212+ core . exportVariable ( EnvVar . JOB_STATUS , JobStatus . SuccessStatus ) ;
213+ core . exportVariable ( EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY , "true" ) ;
214+ core . setOutput ( "analysis-skipped" , "true" ) ;
215+ core . setOutput ( "analysis-skip-reason" , reason ) ;
216+ }
217+
204218async function run (
205219 actionState : ActionState < [ "Base" , "Logger" , "Env" , "Actions" ] > ,
206220) {
@@ -228,6 +242,22 @@ async function run(
228242 // Make inputs accessible in the `post` step.
229243 persistInputs ( ) ;
230244
245+ // This is a workflow configuration error independent of draft state, so
246+ // retain the existing validation before taking the early skip path.
247+ if ( process . env [ EnvVar . SETUP_CODEQL_ACTION_HAS_RUN ] === "true" ) {
248+ throw new ConfigurationError (
249+ `The 'init' action should not be run in the same workflow as 'setup-codeql'.` ,
250+ ) ;
251+ }
252+
253+ const draftSkipReason = getDraftAnalysisSkipReason ( logger ) ;
254+ if ( draftSkipReason !== undefined ) {
255+ // Do not send start/completion status reports here. They make API calls
256+ // before and after the skip, and a draft needs no CodeQL status payload.
257+ markAnalysisSkipped ( draftSkipReason , logger ) ;
258+ return ;
259+ }
260+
231261 apiDetails = {
232262 auth : getRequiredInput ( "token" ) ,
233263 externalRepoAuth : getOptionalInput ( "external-repository-token" ) ,
@@ -290,23 +320,9 @@ async function run(
290320 // Send a status report indicating that an analysis is starting.
291321 await sendStartingStatusReport ( startedAt , { analysisKinds } , logger ) ;
292322
293- // Throw a `ConfigurationError` if the `setup-codeql` action has been run.
294- if ( process . env [ EnvVar . SETUP_CODEQL_ACTION_HAS_RUN ] === "true" ) {
295- throw new ConfigurationError (
296- `The 'init' action should not be run in the same workflow as 'setup-codeql'.` ,
297- ) ;
298- }
299-
300323 const analysisSkipReason = await getAnalysisSkipReason ( logger ) ;
301324 if ( analysisSkipReason !== undefined ) {
302- logger . info (
303- `Skipping CodeQL before tool download and database initialization: ${ analysisSkipReason } .` ,
304- ) ;
305- core . exportVariable ( EnvVar . ANALYSIS_SKIP_REASON , analysisSkipReason ) ;
306- core . exportVariable ( EnvVar . JOB_STATUS , JobStatus . SuccessStatus ) ;
307- core . exportVariable ( EnvVar . ANALYZE_DID_COMPLETE_SUCCESSFULLY , "true" ) ;
308- core . setOutput ( "analysis-skipped" , "true" ) ;
309- core . setOutput ( "analysis-skip-reason" , analysisSkipReason ) ;
325+ markAnalysisSkipped ( analysisSkipReason , logger ) ;
310326 await sendCompletedStatusReport (
311327 startedAt ,
312328 undefined ,
0 commit comments