Skip to content

Commit 67f44bc

Browse files
committed
Use Logger for printDebugLogs and log when returning early
1 parent 26c6f91 commit 67f44bc

4 files changed

Lines changed: 40 additions & 32 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 22 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/actions-util.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { computeAutomationID } from "./api-client";
1313
import { EnvVar } from "./environment";
1414
import { getRunnerLogger } from "./logging";
15-
import { setupTests } from "./testing-utils";
15+
import { RecordingLogger, setupTests } from "./testing-utils";
1616
import { initializeEnvironment, withTmpDir } from "./util";
1717

1818
setupTests(test);
@@ -102,15 +102,17 @@ test("computeAutomationID()", async (t) => {
102102
});
103103

104104
test("printDebugLogs - doesn't throw when config doesn't have needed properties", async (t) => {
105-
await t.notThrowsAsync(printDebugLogs({}));
106-
await t.notThrowsAsync(printDebugLogs({ languages: [] }));
107-
await t.notThrowsAsync(printDebugLogs({ dbLocation: "nowhere" }));
105+
const logger = new RecordingLogger();
106+
await t.notThrowsAsync(printDebugLogs(logger, {}));
107+
await t.notThrowsAsync(printDebugLogs(logger, { languages: [] }));
108+
await t.notThrowsAsync(printDebugLogs(logger, { dbLocation: "nowhere" }));
108109
});
109110

110111
test("printDebugLogs - doesn't throw when language db doesn't exist", async (t) =>
111112
withTmpDir(async (tmpDir) => {
113+
const logger = new RecordingLogger();
112114
await t.notThrowsAsync(
113-
printDebugLogs({ dbLocation: tmpDir, languages: ["javascript"] }),
115+
printDebugLogs(logger, { dbLocation: tmpDir, languages: ["javascript"] }),
114116
);
115117
}));
116118

‎src/actions-util.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,38 @@ export function getWorkflowEvent(env: Env = getEnv()): any {
131131
}
132132
}
133133

134-
export async function printDebugLogs(config: Partial<Config>) {
134+
export async function printDebugLogs(logger: Logger, config: Partial<Config>) {
135135
if (
136136
!hasConfigKey(config, "languages") ||
137137
!hasConfigKey(config, "dbLocation")
138138
) {
139+
logger.debug(
140+
`Not printing debug logs, because the configuration does not include the 'languages' or 'dbLocation' fields.`,
141+
);
139142
return;
140143
}
141144

142145
for (const language of config.languages) {
143146
const databaseDirectory = getCodeQLDatabasePath(config, language);
144147
const logsDirectory = path.join(databaseDirectory, "log");
145148
if (!doesDirectoryExist(logsDirectory)) {
146-
core.info(`Directory ${logsDirectory} does not exist.`);
149+
logger.info(`Directory ${logsDirectory} does not exist.`);
147150
continue; // Skip this language database.
148151
}
149152

150153
const walkLogFiles = (dir: string) => {
151154
const entries = fs.readdirSync(dir, { withFileTypes: true });
152155
if (entries.length === 0) {
153-
core.info(`No debug logs found at directory ${logsDirectory}.`);
156+
logger.info(`No debug logs found at directory ${logsDirectory}.`);
154157
}
155158
for (const entry of entries) {
156159
if (entry.isFile()) {
157160
const absolutePath = path.resolve(dir, entry.name);
158-
core.startGroup(
161+
logger.startGroup(
159162
`CodeQL Debug Logs - ${language} - ${entry.name} from file at path ${absolutePath}`,
160163
);
161-
process.stdout.write(fs.readFileSync(absolutePath));
162-
core.endGroup();
164+
logger.info(fs.readFileSync(absolutePath, "utf-8"));
165+
logger.endGroup();
163166
} else if (entry.isDirectory()) {
164167
walkLogFiles(path.resolve(dir, entry.name));
165168
}

‎src/init-action-post-helper.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export async function uploadFailureInfo(
338338
config: UploadDebugArtifactsConfig,
339339
logger: Logger,
340340
) => Promise<void>,
341-
printDebugLogs: (config: Partial<Config>) => Promise<void>,
341+
printDebugLogs: (logger: Logger, config: Partial<Config>) => Promise<void>,
342342
codeql: CodeQL,
343343
config: Config | AbortedInitConfig,
344344
repositoryNwo: RepositoryNwo,
@@ -392,7 +392,7 @@ export async function uploadFailureInfo(
392392
"Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...",
393393
);
394394
await uploadAllAvailableDebugArtifacts(codeql, config, logger);
395-
await printDebugLogs(config);
395+
await printDebugLogs(logger, config);
396396
}
397397

398398
if (actionsUtil.isSelfHostedRunner() && config.dbLocation) {

0 commit comments

Comments
 (0)