1+ import * as fs from "fs" ;
2+ import * as path from "path" ;
3+
14import * as core from "@actions/core" ;
25
36import * as actionsUtil from "./actions-util" ;
69 CodeQLAnalysisError ,
710 QueriesStatusReport ,
811} from "./analyze" ;
9- import { getConfig } from "./config-utils" ;
12+ import { Config , getConfig } from "./config-utils" ;
1013import { getActionsLogger } from "./logging" ;
1114import { parseRepositoryNwo } from "./repository" ;
1215import * as upload_lib from "./upload-lib" ;
@@ -46,6 +49,7 @@ async function sendStatusReport(
4649async function run ( ) {
4750 const startedAt = new Date ( ) ;
4851 let stats : AnalysisStatusReport | undefined = undefined ;
52+ let config : Config | undefined = undefined ;
4953 try {
5054 actionsUtil . prepareLocalRunEnvironment ( ) ;
5155 if (
@@ -60,7 +64,7 @@ async function run() {
6064 return ;
6165 }
6266 const logger = getActionsLogger ( ) ;
63- const config = await getConfig (
67+ config = await getConfig (
6468 actionsUtil . getRequiredEnvParam ( "RUNNER_TEMP" ) ,
6569 logger
6670 ) ;
@@ -115,6 +119,35 @@ async function run() {
115119
116120 await sendStatusReport ( startedAt , stats , error ) ;
117121 return ;
122+ } finally {
123+ if ( core . isDebug ( ) && config !== undefined ) {
124+ core . info ( "Debug mode is on. Printing CodeQL debug logs..." ) ;
125+ for ( const language of config . languages ) {
126+ const databaseDirectory = util . getCodeQLDatabasePath (
127+ config . tempDir ,
128+ language
129+ ) ;
130+ const logsDirectory = path . join ( databaseDirectory , "log" ) ;
131+
132+ const walkLogFiles = ( dir : string ) => {
133+ const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
134+ for ( const entry of entries ) {
135+ if ( entry . isFile ( ) ) {
136+ core . startGroup (
137+ `CodeQL Debug Logs - ${ language } - ${ entry . name } `
138+ ) ;
139+ process . stdout . write (
140+ fs . readFileSync ( path . resolve ( dir , entry . name ) )
141+ ) ;
142+ core . endGroup ( ) ;
143+ } else if ( entry . isDirectory ( ) ) {
144+ walkLogFiles ( path . resolve ( dir , entry . name ) ) ;
145+ }
146+ }
147+ } ;
148+ walkLogFiles ( logsDirectory ) ;
149+ }
150+ }
118151 }
119152
120153 await sendStatusReport ( startedAt , stats ) ;
0 commit comments