@@ -6,7 +6,7 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
66import * as github from "@actions/github" ;
77import * as io from "@actions/io" ;
88
9- import type { Config } from "./config-utils " ;
9+ import { hasConfigKey , type Config } from "./config/action-config " ;
1010import { Env , EnvVar , ActionsEnvVars , ReadOnlyEnv } from "./environment" ;
1111import { Logger } from "./logging" ;
1212import {
@@ -131,28 +131,38 @@ export function getWorkflowEvent(env: Env = getEnv()): any {
131131 }
132132}
133133
134- export async function printDebugLogs ( config : Config ) {
134+ export async function printDebugLogs ( logger : Logger , config : Partial < Config > ) {
135+ if (
136+ ! hasConfigKey ( config , "languages" ) ||
137+ ! hasConfigKey ( config , "dbLocation" )
138+ ) {
139+ logger . debug (
140+ `Not printing debug logs, because the configuration does not include the 'languages' or 'dbLocation' fields.` ,
141+ ) ;
142+ return ;
143+ }
144+
135145 for ( const language of config . languages ) {
136146 const databaseDirectory = getCodeQLDatabasePath ( config , language ) ;
137147 const logsDirectory = path . join ( databaseDirectory , "log" ) ;
138148 if ( ! doesDirectoryExist ( logsDirectory ) ) {
139- core . info ( `Directory ${ logsDirectory } does not exist.` ) ;
149+ logger . info ( `Directory ${ logsDirectory } does not exist.` ) ;
140150 continue ; // Skip this language database.
141151 }
142152
143153 const walkLogFiles = ( dir : string ) => {
144154 const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
145155 if ( entries . length === 0 ) {
146- core . info ( `No debug logs found at directory ${ logsDirectory } .` ) ;
156+ logger . info ( `No debug logs found at directory ${ logsDirectory } .` ) ;
147157 }
148158 for ( const entry of entries ) {
149159 if ( entry . isFile ( ) ) {
150160 const absolutePath = path . resolve ( dir , entry . name ) ;
151- core . startGroup (
161+ logger . startGroup (
152162 `CodeQL Debug Logs - ${ language } - ${ entry . name } from file at path ${ absolutePath } ` ,
153163 ) ;
154- process . stdout . write ( fs . readFileSync ( absolutePath ) ) ;
155- core . endGroup ( ) ;
164+ logger . info ( fs . readFileSync ( absolutePath , "utf-8" ) ) ;
165+ logger . endGroup ( ) ;
156166 } else if ( entry . isDirectory ( ) ) {
157167 walkLogFiles ( path . resolve ( dir , entry . name ) ) ;
158168 }
0 commit comments