Skip to content

Commit 24872f6

Browse files
authored
Merge pull request #374 from github/automatic-upload-debug-logs
Upload debug logs automatically when `ACTIONS_STEP_DEBUG` is enabled.
2 parents 7a340d3 + 94b3288 commit 24872f6

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

lib/analyze-action.js

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
14
import * as core from "@actions/core";
25

36
import * as actionsUtil from "./actions-util";
@@ -6,7 +9,7 @@ import {
69
CodeQLAnalysisError,
710
QueriesStatusReport,
811
} from "./analyze";
9-
import { getConfig } from "./config-utils";
12+
import { Config, getConfig } from "./config-utils";
1013
import { getActionsLogger } from "./logging";
1114
import { parseRepositoryNwo } from "./repository";
1215
import * as upload_lib from "./upload-lib";
@@ -46,6 +49,7 @@ async function sendStatusReport(
4649
async 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

Comments
 (0)