2020-04-28 16:46:47 +02:00
|
|
|
"use strict";
|
2021-07-27 17:59:59 +01:00
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
2020-04-28 16:46:47 +02:00
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
2021-07-27 17:59:59 +01:00
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
2020-04-28 16:46:47 +02:00
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2021-06-29 16:00:55 -05:00
|
|
|
const path = __importStar(require("path"));
|
2021-06-29 16:17:28 -05:00
|
|
|
const core = __importStar(require("@actions/core"));
|
2021-05-20 15:20:32 -07:00
|
|
|
const actions_util_1 = require("./actions-util");
|
2022-03-14 08:20:27 -07:00
|
|
|
const api_client_1 = require("./api-client");
|
2021-09-15 14:49:20 +01:00
|
|
|
const codeql_1 = require("./codeql");
|
2021-12-15 13:34:29 +00:00
|
|
|
const feature_flags_1 = require("./feature-flags");
|
2020-08-25 16:19:15 +01:00
|
|
|
const init_1 = require("./init");
|
2020-10-06 11:30:05 +02:00
|
|
|
const languages_1 = require("./languages");
|
2020-08-25 16:19:15 +01:00
|
|
|
const logging_1 = require("./logging");
|
2020-08-27 10:46:26 +01:00
|
|
|
const repository_1 = require("./repository");
|
2020-11-26 17:54:34 +00:00
|
|
|
const util_1 = require("./util");
|
2021-06-01 14:49:07 -07:00
|
|
|
// eslint-disable-next-line import/no-commonjs
|
|
|
|
|
const pkg = require("../package.json");
|
2020-11-11 18:22:12 +00:00
|
|
|
async function sendSuccessStatusReport(startedAt, config, toolsVersion) {
|
2020-09-17 17:29:45 +01:00
|
|
|
var _a;
|
2021-09-10 13:53:13 -07:00
|
|
|
const statusReportBase = await (0, actions_util_1.createStatusReportBase)("init", "success", startedAt);
|
2020-09-14 10:44:43 +01:00
|
|
|
const languages = config.languages.join(",");
|
2021-09-10 13:53:13 -07:00
|
|
|
const workflowLanguages = (0, actions_util_1.getOptionalInput)("languages");
|
2020-09-14 10:44:43 +01:00
|
|
|
const paths = (config.originalUserInput.paths || []).join(",");
|
|
|
|
|
const pathsIgnore = (config.originalUserInput["paths-ignore"] || []).join(",");
|
|
|
|
|
const disableDefaultQueries = config.originalUserInput["disable-default-queries"]
|
|
|
|
|
? languages
|
|
|
|
|
: "";
|
2020-09-17 17:29:45 +01:00
|
|
|
const queries = [];
|
2021-09-10 13:53:13 -07:00
|
|
|
let queriesInput = (_a = (0, actions_util_1.getOptionalInput)("queries")) === null || _a === void 0 ? void 0 : _a.trim();
|
2020-09-17 17:29:45 +01:00
|
|
|
if (queriesInput === undefined || queriesInput.startsWith("+")) {
|
|
|
|
|
queries.push(...(config.originalUserInput.queries || []).map((q) => q.uses));
|
|
|
|
|
}
|
|
|
|
|
if (queriesInput !== undefined) {
|
|
|
|
|
queriesInput = queriesInput.startsWith("+")
|
2022-03-20 05:55:28 +01:00
|
|
|
? queriesInput.slice(1)
|
2020-09-17 17:29:45 +01:00
|
|
|
: queriesInput;
|
|
|
|
|
queries.push(...queriesInput.split(","));
|
|
|
|
|
}
|
2020-07-20 16:33:37 +01:00
|
|
|
const statusReport = {
|
|
|
|
|
...statusReportBase,
|
2022-02-03 11:52:49 +00:00
|
|
|
disable_default_queries: disableDefaultQueries,
|
2020-09-14 10:44:43 +01:00
|
|
|
languages,
|
2022-02-09 12:56:31 +00:00
|
|
|
ml_powered_javascript_queries: (0, util_1.getMlPoweredJsQueriesStatus)(config),
|
2020-09-14 10:44:43 +01:00
|
|
|
paths,
|
2020-07-20 16:33:37 +01:00
|
|
|
paths_ignore: pathsIgnore,
|
2020-09-17 17:29:45 +01:00
|
|
|
queries: queries.join(","),
|
2021-09-10 13:53:13 -07:00
|
|
|
tools_input: (0, actions_util_1.getOptionalInput)("tools") || "",
|
2020-11-11 18:22:12 +00:00
|
|
|
tools_resolved_version: toolsVersion,
|
2022-02-03 11:52:49 +00:00
|
|
|
workflow_languages: workflowLanguages || "",
|
2020-07-20 16:33:37 +01:00
|
|
|
};
|
2021-09-10 13:53:13 -07:00
|
|
|
await (0, actions_util_1.sendStatusReport)(statusReport);
|
2020-07-20 16:33:37 +01:00
|
|
|
}
|
2020-04-28 16:46:47 +02:00
|
|
|
async function run() {
|
2020-07-20 16:33:37 +01:00
|
|
|
const startedAt = new Date();
|
2021-09-10 13:53:13 -07:00
|
|
|
const logger = (0, logging_1.getActionsLogger)();
|
|
|
|
|
(0, util_1.initializeEnvironment)(util_1.Mode.actions, pkg.version);
|
2022-04-26 16:45:44 +01:00
|
|
|
await (0, util_1.checkActionVersion)(pkg.version);
|
2020-06-26 15:33:59 +01:00
|
|
|
let config;
|
|
|
|
|
let codeql;
|
2020-11-11 18:22:12 +00:00
|
|
|
let toolsVersion;
|
2020-11-26 17:54:34 +00:00
|
|
|
const apiDetails = {
|
2021-09-10 13:53:13 -07:00
|
|
|
auth: (0, actions_util_1.getRequiredInput)("token"),
|
|
|
|
|
externalRepoAuth: (0, actions_util_1.getOptionalInput)("external-repository-token"),
|
|
|
|
|
url: (0, util_1.getRequiredEnvParam)("GITHUB_SERVER_URL"),
|
2020-11-26 17:54:34 +00:00
|
|
|
};
|
2022-03-14 15:44:16 -07:00
|
|
|
const gitHubVersion = await (0, api_client_1.getGitHubVersionActionsOnly)();
|
2021-09-10 13:53:13 -07:00
|
|
|
(0, util_1.checkGitHubVersionInRange)(gitHubVersion, logger, util_1.Mode.actions);
|
2021-12-15 13:34:29 +00:00
|
|
|
const repositoryNwo = (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY"));
|
|
|
|
|
const featureFlags = new feature_flags_1.GitHubFeatureFlags(gitHubVersion, apiDetails, repositoryNwo, logger);
|
2020-04-28 16:46:47 +02:00
|
|
|
try {
|
2021-09-10 13:53:13 -07:00
|
|
|
const workflowErrors = await (0, actions_util_1.validateWorkflow)();
|
|
|
|
|
if (!(await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", "starting", startedAt, workflowErrors)))) {
|
2020-04-28 16:46:47 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-09-10 13:53:13 -07:00
|
|
|
const initCodeQLResult = await (0, init_1.initCodeQL)((0, actions_util_1.getOptionalInput)("tools"), apiDetails, (0, actions_util_1.getTemporaryDirectory)(), (0, actions_util_1.getToolCacheDirectory)(), gitHubVersion.type, logger);
|
2020-11-11 18:22:12 +00:00
|
|
|
codeql = initCodeQLResult.codeql;
|
|
|
|
|
toolsVersion = initCodeQLResult.toolsVersion;
|
2021-09-15 14:49:20 +01:00
|
|
|
await (0, util_1.enrichEnvironment)(util_1.Mode.actions, codeql);
|
2022-01-07 13:11:51 +00:00
|
|
|
config = await (0, init_1.initConfig)((0, actions_util_1.getOptionalInput)("languages"), (0, actions_util_1.getOptionalInput)("queries"), (0, actions_util_1.getOptionalInput)("packs"), (0, actions_util_1.getOptionalInput)("config-file"), (0, actions_util_1.getOptionalInput)("db-location"), (0, actions_util_1.getOptionalInput)("debug") === "true", (0, actions_util_1.getOptionalInput)("debug-artifact-name") || util_1.DEFAULT_DEBUG_ARTIFACT_NAME, (0, actions_util_1.getOptionalInput)("debug-database-name") || util_1.DEFAULT_DEBUG_DATABASE_NAME, repositoryNwo, (0, actions_util_1.getTemporaryDirectory)(), (0, util_1.getRequiredEnvParam)("RUNNER_TOOL_CACHE"), codeql, (0, util_1.getRequiredEnvParam)("GITHUB_WORKSPACE"), gitHubVersion, apiDetails, featureFlags, logger);
|
2020-10-27 10:06:17 +01:00
|
|
|
if (config.languages.includes(languages_1.Language.python) &&
|
2021-09-10 13:53:13 -07:00
|
|
|
(0, actions_util_1.getRequiredInput)("setup-python-dependencies") === "true") {
|
2020-10-06 11:30:05 +02:00
|
|
|
try {
|
2021-09-10 13:53:13 -07:00
|
|
|
await (0, init_1.installPythonDeps)(codeql, logger);
|
2020-10-06 11:30:05 +02:00
|
|
|
}
|
|
|
|
|
catch (err) {
|
2021-09-10 13:53:13 -07:00
|
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
|
|
|
logger.warning(`${message} You can call this action with 'setup-python-dependencies: false' to disable this process`);
|
2020-10-06 11:30:05 +02:00
|
|
|
}
|
2020-09-11 10:53:41 +02:00
|
|
|
}
|
2020-06-23 18:36:08 +02:00
|
|
|
}
|
|
|
|
|
catch (e) {
|
2021-09-10 13:53:13 -07:00
|
|
|
const message = e instanceof Error ? e.message : String(e);
|
|
|
|
|
core.setFailed(message);
|
2020-08-05 09:40:28 +01:00
|
|
|
console.log(e);
|
2021-09-10 13:53:13 -07:00
|
|
|
await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", "aborted", startedAt, message));
|
2020-06-23 18:36:08 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
2020-04-28 16:46:47 +02:00
|
|
|
// Forward Go flags
|
2020-09-14 10:44:43 +01:00
|
|
|
const goFlags = process.env["GOFLAGS"];
|
2020-04-28 16:46:47 +02:00
|
|
|
if (goFlags) {
|
2020-09-14 10:44:43 +01:00
|
|
|
core.exportVariable("GOFLAGS", goFlags);
|
2020-04-28 16:46:47 +02:00
|
|
|
core.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.");
|
|
|
|
|
}
|
2021-10-28 15:09:59 -07:00
|
|
|
// Limit RAM and threads for extractors. When running extractors, the CodeQL CLI obeys the
|
|
|
|
|
// CODEQL_RAM and CODEQL_THREADS environment variables to decide how much RAM and how many
|
|
|
|
|
// threads it would ask extractors to use. See help text for the "--ram" and "--threads"
|
|
|
|
|
// options at https://codeql.github.com/docs/codeql-cli/manual/database-trace-command/
|
|
|
|
|
// for details.
|
|
|
|
|
core.exportVariable("CODEQL_RAM", process.env["CODEQL_RAM"] ||
|
|
|
|
|
(0, util_1.getMemoryFlagValue)((0, actions_util_1.getOptionalInput)("ram")).toString());
|
|
|
|
|
core.exportVariable("CODEQL_THREADS", (0, util_1.getThreadsFlagValue)((0, actions_util_1.getOptionalInput)("threads"), logger).toString());
|
2021-09-10 13:53:13 -07:00
|
|
|
const sourceRoot = path.resolve((0, util_1.getRequiredEnvParam)("GITHUB_WORKSPACE"), (0, actions_util_1.getOptionalInput)("source-root") || "");
|
2021-09-15 14:49:20 +01:00
|
|
|
const tracerConfig = await (0, init_1.runInit)(codeql, config, sourceRoot, "Runner.Worker.exe", undefined);
|
2020-08-24 12:53:09 +01:00
|
|
|
if (tracerConfig !== undefined) {
|
2020-09-20 17:03:01 +08:00
|
|
|
for (const [key, value] of Object.entries(tracerConfig.env)) {
|
|
|
|
|
core.exportVariable(key, value);
|
|
|
|
|
}
|
2021-09-15 14:49:20 +01:00
|
|
|
if (process.platform === "win32" &&
|
|
|
|
|
!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_NEW_TRACING))) {
|
2021-09-10 13:53:13 -07:00
|
|
|
await (0, init_1.injectWindowsTracer)("Runner.Worker.exe", undefined, config, codeql, tracerConfig);
|
2020-09-07 13:36:47 +01:00
|
|
|
}
|
2020-04-28 16:46:47 +02:00
|
|
|
}
|
2020-11-04 19:10:27 +00:00
|
|
|
core.setOutput("codeql-path", config.codeQLCmd);
|
2020-04-28 16:46:47 +02:00
|
|
|
}
|
|
|
|
|
catch (error) {
|
2021-09-10 13:53:13 -07:00
|
|
|
core.setFailed(String(error));
|
2020-08-05 09:40:28 +01:00
|
|
|
console.log(error);
|
2022-02-17 11:47:04 -08:00
|
|
|
await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", (0, actions_util_1.getActionsStatus)(error), startedAt, String(error), error instanceof Error ? error.stack : undefined));
|
2020-04-28 16:46:47 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-11-11 18:22:12 +00:00
|
|
|
await sendSuccessStatusReport(startedAt, config, toolsVersion);
|
2020-04-28 16:46:47 +02:00
|
|
|
}
|
2020-11-25 22:46:30 +01:00
|
|
|
async function runWrapper() {
|
|
|
|
|
try {
|
|
|
|
|
await run();
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
core.setFailed(`init action failed: ${error}`);
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void runWrapper();
|
2020-08-24 15:09:02 +01:00
|
|
|
//# sourceMappingURL=init-action.js.map
|