Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 65 additions & 31 deletions lib/entry-points.js

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

22 changes: 16 additions & 6 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getCodeQLDatabasePath,
ConfigurationError,
getEnv,
getErrorMessage,
} from "./util";

/**
Expand Down Expand Up @@ -412,14 +413,23 @@ export const persistInputs = function (env: Env = getEnv()) {
/**
* Restores all inputs to the action from the persisted state.
*/
export const restoreInputs = function () {
const persistedInputs = core.getState(persistedInputsKey);
if (persistedInputs) {
for (const [name, value] of JSON.parse(persistedInputs)) {
process.env[name] = value;
export function restoreInputs(logger: Logger) {
try {
const persistedInputsValue = core.getState(persistedInputsKey);
if (persistedInputsValue) {
const persistedInputs = JSON.parse(persistedInputsValue);

for (const [name, value] of persistedInputs) {
process.env[name] = value;
}
}
} catch (err) {
logger.error(`Unable to restore inputs: ${getErrorMessage(err)}`);
throw new Error(
"Failed to restore inputs from the state set by this action's main execution.",
);
}
};
}

export interface PullRequestBranches {
base: string;
Expand Down
2 changes: 1 addition & 1 deletion src/analyze-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function runWrapper() {
// possible, and only use safe functions outside.

try {
actionsUtil.restoreInputs();
const logger = getActionsLogger();
actionsUtil.restoreInputs(logger);
const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);

Expand Down
8 changes: 7 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,13 @@ async function getCodeQLForCmd(
},
},
).exec();
return JSON.parse(extractorPath) as string;
try {
return JSON.parse(extractorPath) as string;
} catch (err) {
throw new Error(
`Failed to parse extractor path for '${language}' from CLI: ${getErrorMessage(err)}\nOutput was: ${extractorPath}`,
);
}
},
async resolveQueriesStartingPacks(queries: string[]): Promise<string[]> {
const codeqlArgs = [
Expand Down
2 changes: 1 addition & 1 deletion src/init-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function run(startedAt: Date) {
const jobStatus = getOptionalInput("job-status");

// Restore inputs from `init` Action.
restoreInputs();
restoreInputs(logger);

const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);
Expand Down
2 changes: 1 addition & 1 deletion src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ async function run(
);
}

const tracerConfig = await getCombinedTracerConfig(codeql, config);
const tracerConfig = await getCombinedTracerConfig(logger, codeql, config);
if (tracerConfig !== undefined) {
for (const [key, value] of Object.entries(tracerConfig.env)) {
core.exportVariable(key, value);
Expand Down
9 changes: 8 additions & 1 deletion src/sarif/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";

import { Logger } from "../logging";
import { getErrorMessage } from "../util";

import * as sarif from "sarif";

Expand Down Expand Up @@ -48,7 +49,13 @@ export function getToolNames(sarifFile: Partial<sarif.Log>): string[] {
* @returns The resulting JSON value, cast to a SARIF `Log`.
*/
export function readSarifFile(sarifFilePath: string): Partial<sarif.Log> {
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
try {
return JSON.parse(fs.readFileSync(sarifFilePath, "utf8")) as sarif.Log;
} catch (err) {
throw new Error(
`Parsing SARIF file at '${sarifFilePath}' failed: ${getErrorMessage(err)}`,
);
}
}

// Takes a list of paths to sarif files and combines them together,
Expand Down
2 changes: 1 addition & 1 deletion src/start-proxy-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function runWrapper() {

try {
// Restore inputs from `start-proxy` Action.
actionsUtil.restoreInputs();
actionsUtil.restoreInputs(logger);

// Kill the running proxy
const pid = core.getState("proxy-process-pid");
Expand Down
17 changes: 14 additions & 3 deletions src/tracer-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import * as sinon from "sinon";
import { CodeQL, getCodeQLForTesting } from "./codeql";
import * as configUtils from "./config-utils";
import { BuiltInLanguage } from "./languages";
import { createTestConfig, makeVersionInfo, setupTests } from "./testing-utils";
import {
createTestConfig,
makeVersionInfo,
RecordingLogger,
setupTests,
} from "./testing-utils";
import { ToolsFeature } from "./tools-features";
import { getCombinedTracerConfig } from "./tracer-config";
import * as util from "./util";
Expand Down Expand Up @@ -42,18 +47,20 @@ async function stubCodeql(
}

test("getCombinedTracerConfig - return undefined when no languages are traced languages", async (t) => {
const logger = new RecordingLogger();
await util.withTmpDir(async (tmpDir) => {
const config = getTestConfig(tmpDir);
// No traced languages
config.languages = [BuiltInLanguage.javascript, BuiltInLanguage.python];
t.deepEqual(
await getCombinedTracerConfig(await stubCodeql(), config),
await getCombinedTracerConfig(logger, await stubCodeql(), config),
undefined,
);
});
});

test("getCombinedTracerConfig", async (t) => {
const logger = new RecordingLogger();
await util.withTmpDir(async (tmpDir) => {
const config = getTestConfig(tmpDir);

Expand Down Expand Up @@ -82,7 +89,11 @@ test("getCombinedTracerConfig", async (t) => {
);
fs.writeFileSync(startTracingJson, JSON.stringify(startTracingEnv));

const result = await getCombinedTracerConfig(await stubCodeql(), config);
const result = await getCombinedTracerConfig(
logger,
await stubCodeql(),
config,
);
t.notDeepEqual(result, undefined);

t.false(Object.prototype.hasOwnProperty.call(result?.env, "CODEQL_RUNNER"));
Expand Down
Loading
Loading