Skip to content

Commit

Permalink
Merge pull request #374 from github/automatic-upload-debug-logs
Browse files Browse the repository at this point in the history
Upload debug logs automatically when `ACTIONS_STEP_DEBUG` is enabled.
  • Loading branch information
Chris Gavin authored and GitHub committed Jan 26, 2021
2 parents 7a340d3 + 94b3288 commit 24872f6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
28 changes: 27 additions & 1 deletion lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions src/analyze-action.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as fs from "fs";
import * as path from "path";

import * as core from "@actions/core";

import * as actionsUtil from "./actions-util";
Expand All @@ -6,7 +9,7 @@ import {
CodeQLAnalysisError,
QueriesStatusReport,
} from "./analyze";
import { getConfig } from "./config-utils";
import { Config, getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import * as upload_lib from "./upload-lib";
Expand Down Expand Up @@ -46,6 +49,7 @@ async function sendStatusReport(
async function run() {
const startedAt = new Date();
let stats: AnalysisStatusReport | undefined = undefined;
let config: Config | undefined = undefined;
try {
actionsUtil.prepareLocalRunEnvironment();
if (
Expand All @@ -60,7 +64,7 @@ async function run() {
return;
}
const logger = getActionsLogger();
const config = await getConfig(
config = await getConfig(
actionsUtil.getRequiredEnvParam("RUNNER_TEMP"),
logger
);
Expand Down Expand Up @@ -115,6 +119,35 @@ async function run() {

await sendStatusReport(startedAt, stats, error);
return;
} finally {
if (core.isDebug() && config !== undefined) {
core.info("Debug mode is on. Printing CodeQL debug logs...");
for (const language of config.languages) {
const databaseDirectory = util.getCodeQLDatabasePath(
config.tempDir,
language
);
const logsDirectory = path.join(databaseDirectory, "log");

const walkLogFiles = (dir: string) => {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isFile()) {
core.startGroup(
`CodeQL Debug Logs - ${language} - ${entry.name}`
);
process.stdout.write(
fs.readFileSync(path.resolve(dir, entry.name))
);
core.endGroup();
} else if (entry.isDirectory()) {
walkLogFiles(path.resolve(dir, entry.name));
}
}
};
walkLogFiles(logsDirectory);
}
}
}

await sendStatusReport(startedAt, stats);
Expand Down

0 comments on commit 24872f6

Please sign in to comment.