diff --git a/lib/entry-points.js b/lib/entry-points.js index 3c5ee3bd2..600323420 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -21656,8 +21656,8 @@ var require_core = __commonJS({ exports2.warning = warning14; exports2.notice = notice; exports2.info = info8; - exports2.startGroup = startGroup4; - exports2.endGroup = endGroup4; + exports2.startGroup = startGroup3; + exports2.endGroup = endGroup3; exports2.group = group; exports2.saveState = saveState3; exports2.getState = getState3; @@ -21755,20 +21755,20 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); function info8(message) { process.stdout.write(message + os7.EOL); } - function startGroup4(name) { + function startGroup3(name) { (0, command_1.issue)("group", name); } - function endGroup4() { + function endGroup3() { (0, command_1.issue)("endgroup"); } function group(name, fn) { return __awaiter2(this, void 0, void 0, function* () { - startGroup4(name); + startGroup3(name); let result; try { result = yield fn(); } finally { - endGroup4(); + endGroup3(); } return result; }); @@ -145686,22 +145686,22 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); process.stdout.write(message + os7.EOL); } exports2.info = info8; - function startGroup4(name) { + function startGroup3(name) { (0, command_1.issue)("group", name); } - exports2.startGroup = startGroup4; - function endGroup4() { + exports2.startGroup = startGroup3; + function endGroup3() { (0, command_1.issue)("endgroup"); } - exports2.endGroup = endGroup4; + exports2.endGroup = endGroup3; function group(name, fn) { return __awaiter2(this, void 0, void 0, function* () { - startGroup4(name); + startGroup3(name); let result; try { result = yield fn(); } finally { - endGroup4(); + endGroup3(); } return result; }); @@ -170212,30 +170212,33 @@ function getWorkflowEvent(env = getEnv()) { ); } } -async function printDebugLogs(config) { +async function printDebugLogs(logger2, config) { if (!hasConfigKey(config, "languages") || !hasConfigKey(config, "dbLocation")) { + logger2.debug( + `Not printing debug logs, because the configuration does not include the 'languages' or 'dbLocation' fields.` + ); return; } for (const language of config.languages) { const databaseDirectory = getCodeQLDatabasePath(config, language); const logsDirectory = path2.join(databaseDirectory, "log"); if (!doesDirectoryExist(logsDirectory)) { - core4.info(`Directory ${logsDirectory} does not exist.`); + logger2.info(`Directory ${logsDirectory} does not exist.`); continue; } const walkLogFiles = (dir) => { const entries = fs2.readdirSync(dir, { withFileTypes: true }); if (entries.length === 0) { - core4.info(`No debug logs found at directory ${logsDirectory}.`); + logger2.info(`No debug logs found at directory ${logsDirectory}.`); } for (const entry of entries) { if (entry.isFile()) { const absolutePath = path2.resolve(dir, entry.name); - core4.startGroup( + logger2.startGroup( `CodeQL Debug Logs - ${language} - ${entry.name} from file at path ${absolutePath}` ); - process.stdout.write(fs2.readFileSync(absolutePath)); - core4.endGroup(); + logger2.info(fs2.readFileSync(absolutePath, "utf-8")); + logger2.endGroup(); } else if (entry.isDirectory()) { walkLogFiles(path2.resolve(dir, entry.name)); } @@ -186989,7 +186992,7 @@ async function uploadFailureInfo(uploadAllAvailableDebugArtifacts, printDebugLog "Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..." ); await uploadAllAvailableDebugArtifacts(codeql, config, logger2); - await printDebugLogs2(config); + await printDebugLogs2(logger2, config); } if (isSelfHostedRunner() && config.dbLocation) { try { diff --git a/src/actions-util.test.ts b/src/actions-util.test.ts index 1217e831a..17cf96a4a 100644 --- a/src/actions-util.test.ts +++ b/src/actions-util.test.ts @@ -12,7 +12,7 @@ import { import { computeAutomationID } from "./api-client"; import { EnvVar } from "./environment"; import { getRunnerLogger } from "./logging"; -import { setupTests } from "./testing-utils"; +import { RecordingLogger, setupTests } from "./testing-utils"; import { initializeEnvironment, withTmpDir } from "./util"; setupTests(test); @@ -102,15 +102,17 @@ test("computeAutomationID()", async (t) => { }); test("printDebugLogs - doesn't throw when config doesn't have needed properties", async (t) => { - await t.notThrowsAsync(printDebugLogs({})); - await t.notThrowsAsync(printDebugLogs({ languages: [] })); - await t.notThrowsAsync(printDebugLogs({ dbLocation: "nowhere" })); + const logger = new RecordingLogger(); + await t.notThrowsAsync(printDebugLogs(logger, {})); + await t.notThrowsAsync(printDebugLogs(logger, { languages: [] })); + await t.notThrowsAsync(printDebugLogs(logger, { dbLocation: "nowhere" })); }); test("printDebugLogs - doesn't throw when language db doesn't exist", async (t) => withTmpDir(async (tmpDir) => { + const logger = new RecordingLogger(); await t.notThrowsAsync( - printDebugLogs({ dbLocation: tmpDir, languages: ["javascript"] }), + printDebugLogs(logger, { dbLocation: tmpDir, languages: ["javascript"] }), ); })); diff --git a/src/actions-util.ts b/src/actions-util.ts index e43abbb0b..62ab42440 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -131,11 +131,14 @@ export function getWorkflowEvent(env: Env = getEnv()): any { } } -export async function printDebugLogs(config: Partial) { +export async function printDebugLogs(logger: Logger, config: Partial) { if ( !hasConfigKey(config, "languages") || !hasConfigKey(config, "dbLocation") ) { + logger.debug( + `Not printing debug logs, because the configuration does not include the 'languages' or 'dbLocation' fields.`, + ); return; } @@ -143,23 +146,23 @@ export async function printDebugLogs(config: Partial) { const databaseDirectory = getCodeQLDatabasePath(config, language); const logsDirectory = path.join(databaseDirectory, "log"); if (!doesDirectoryExist(logsDirectory)) { - core.info(`Directory ${logsDirectory} does not exist.`); + logger.info(`Directory ${logsDirectory} does not exist.`); continue; // Skip this language database. } const walkLogFiles = (dir: string) => { const entries = fs.readdirSync(dir, { withFileTypes: true }); if (entries.length === 0) { - core.info(`No debug logs found at directory ${logsDirectory}.`); + logger.info(`No debug logs found at directory ${logsDirectory}.`); } for (const entry of entries) { if (entry.isFile()) { const absolutePath = path.resolve(dir, entry.name); - core.startGroup( + logger.startGroup( `CodeQL Debug Logs - ${language} - ${entry.name} from file at path ${absolutePath}`, ); - process.stdout.write(fs.readFileSync(absolutePath)); - core.endGroup(); + logger.info(fs.readFileSync(absolutePath, "utf-8")); + logger.endGroup(); } else if (entry.isDirectory()) { walkLogFiles(path.resolve(dir, entry.name)); } diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 3d3ffc570..e9ebf93a3 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -338,7 +338,7 @@ export async function uploadFailureInfo( config: UploadDebugArtifactsConfig, logger: Logger, ) => Promise, - printDebugLogs: (config: Partial) => Promise, + printDebugLogs: (logger: Logger, config: Partial) => Promise, codeql: CodeQL, config: Config | AbortedInitConfig, repositoryNwo: RepositoryNwo, @@ -392,7 +392,7 @@ export async function uploadFailureInfo( "Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...", ); await uploadAllAvailableDebugArtifacts(codeql, config, logger); - await printDebugLogs(config); + await printDebugLogs(logger, config); } if (actionsUtil.isSelfHostedRunner() && config.dbLocation) {