Send the version and mode with the user agent
This commit changes the way the action determines if running in action or runner mode. There is now an environment variable that is set at the beginning of the process and elsewhere in the process, we can check to see if the variable is set.
This commit is contained in:
parent
fad7cc482d
commit
47588796b4
48 changed files with 361 additions and 224 deletions
|
|
@ -1,6 +1,19 @@
|
|||
import * as core from "@actions/core";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import {
|
||||
createStatusReportBase,
|
||||
getOptionalInput,
|
||||
getRequiredEnvParam,
|
||||
getRequiredInput,
|
||||
getTemporaryDirectory,
|
||||
getToolCacheDirectory,
|
||||
Mode,
|
||||
prepareLocalRunEnvironment,
|
||||
sendStatusReport,
|
||||
setMode,
|
||||
StatusReportBase,
|
||||
validateWorkflow,
|
||||
} from "./actions-util";
|
||||
import { CodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import {
|
||||
|
|
@ -15,7 +28,7 @@ import { getActionsLogger } from "./logging";
|
|||
import { parseRepositoryNwo } from "./repository";
|
||||
import { checkGitHubVersionInRange, getGitHubVersion } from "./util";
|
||||
|
||||
interface InitSuccessStatusReport extends actionsUtil.StatusReportBase {
|
||||
interface InitSuccessStatusReport extends StatusReportBase {
|
||||
// Comma-separated list of languages that analysis was run for
|
||||
// This may be from the workflow file or may be calculated from repository contents
|
||||
languages: string;
|
||||
|
|
@ -40,14 +53,14 @@ async function sendSuccessStatusReport(
|
|||
config: configUtils.Config,
|
||||
toolsVersion: string
|
||||
) {
|
||||
const statusReportBase = await actionsUtil.createStatusReportBase(
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
"init",
|
||||
"success",
|
||||
startedAt
|
||||
);
|
||||
|
||||
const languages = config.languages.join(",");
|
||||
const workflowLanguages = actionsUtil.getOptionalInput("languages");
|
||||
const workflowLanguages = getOptionalInput("languages");
|
||||
const paths = (config.originalUserInput.paths || []).join(",");
|
||||
const pathsIgnore = (config.originalUserInput["paths-ignore"] || []).join(
|
||||
","
|
||||
|
|
@ -59,7 +72,7 @@ async function sendSuccessStatusReport(
|
|||
: "";
|
||||
|
||||
const queries: string[] = [];
|
||||
let queriesInput = actionsUtil.getOptionalInput("queries")?.trim();
|
||||
let queriesInput = getOptionalInput("queries")?.trim();
|
||||
if (queriesInput === undefined || queriesInput.startsWith("+")) {
|
||||
queries.push(
|
||||
...(config.originalUserInput.queries || []).map((q) => q.uses)
|
||||
|
|
@ -80,37 +93,39 @@ async function sendSuccessStatusReport(
|
|||
paths_ignore: pathsIgnore,
|
||||
disable_default_queries: disableDefaultQueries,
|
||||
queries: queries.join(","),
|
||||
tools_input: actionsUtil.getOptionalInput("tools") || "",
|
||||
tools_input: getOptionalInput("tools") || "",
|
||||
tools_resolved_version: toolsVersion,
|
||||
};
|
||||
|
||||
await actionsUtil.sendStatusReport(statusReport);
|
||||
await sendStatusReport(statusReport);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
setMode(Mode.actions);
|
||||
|
||||
let config: configUtils.Config;
|
||||
let codeql: CodeQL;
|
||||
let toolsVersion: string;
|
||||
|
||||
const apiDetails = {
|
||||
auth: actionsUtil.getRequiredInput("token"),
|
||||
externalRepoAuth: actionsUtil.getOptionalInput("external-repository-token"),
|
||||
url: actionsUtil.getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
auth: getRequiredInput("token"),
|
||||
externalRepoAuth: getOptionalInput("external-repository-token"),
|
||||
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
};
|
||||
|
||||
const gitHubVersion = await getGitHubVersion(apiDetails);
|
||||
checkGitHubVersionInRange(gitHubVersion, "actions", logger);
|
||||
checkGitHubVersionInRange(gitHubVersion, logger, Mode.actions);
|
||||
|
||||
try {
|
||||
actionsUtil.prepareLocalRunEnvironment();
|
||||
prepareLocalRunEnvironment();
|
||||
|
||||
const workflowErrors = await actionsUtil.validateWorkflow();
|
||||
const workflowErrors = await validateWorkflow();
|
||||
|
||||
if (
|
||||
!(await actionsUtil.sendStatusReport(
|
||||
await actionsUtil.createStatusReportBase(
|
||||
!(await sendStatusReport(
|
||||
await createStatusReportBase(
|
||||
"init",
|
||||
"starting",
|
||||
startedAt,
|
||||
|
|
@ -122,11 +137,10 @@ async function run() {
|
|||
}
|
||||
|
||||
const initCodeQLResult = await initCodeQL(
|
||||
actionsUtil.getOptionalInput("tools"),
|
||||
getOptionalInput("tools"),
|
||||
apiDetails,
|
||||
actionsUtil.getTemporaryDirectory(),
|
||||
actionsUtil.getToolCacheDirectory(),
|
||||
"actions",
|
||||
getTemporaryDirectory(),
|
||||
getToolCacheDirectory(),
|
||||
gitHubVersion.type,
|
||||
logger
|
||||
);
|
||||
|
|
@ -134,15 +148,15 @@ async function run() {
|
|||
toolsVersion = initCodeQLResult.toolsVersion;
|
||||
|
||||
config = await initConfig(
|
||||
actionsUtil.getOptionalInput("languages"),
|
||||
actionsUtil.getOptionalInput("queries"),
|
||||
actionsUtil.getOptionalInput("config-file"),
|
||||
actionsUtil.getOptionalInput("db-location"),
|
||||
parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")),
|
||||
actionsUtil.getTemporaryDirectory(),
|
||||
actionsUtil.getRequiredEnvParam("RUNNER_TOOL_CACHE"),
|
||||
getOptionalInput("languages"),
|
||||
getOptionalInput("queries"),
|
||||
getOptionalInput("config-file"),
|
||||
getOptionalInput("db-location"),
|
||||
parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")),
|
||||
getTemporaryDirectory(),
|
||||
getRequiredEnvParam("RUNNER_TOOL_CACHE"),
|
||||
codeql,
|
||||
actionsUtil.getRequiredEnvParam("GITHUB_WORKSPACE"),
|
||||
getRequiredEnvParam("GITHUB_WORKSPACE"),
|
||||
gitHubVersion,
|
||||
apiDetails,
|
||||
logger
|
||||
|
|
@ -150,7 +164,7 @@ async function run() {
|
|||
|
||||
if (
|
||||
config.languages.includes(Language.python) &&
|
||||
actionsUtil.getRequiredInput("setup-python-dependencies") === "true"
|
||||
getRequiredInput("setup-python-dependencies") === "true"
|
||||
) {
|
||||
try {
|
||||
await installPythonDeps(codeql, logger);
|
||||
|
|
@ -163,13 +177,8 @@ async function run() {
|
|||
} catch (e) {
|
||||
core.setFailed(e.message);
|
||||
console.log(e);
|
||||
await actionsUtil.sendStatusReport(
|
||||
await actionsUtil.createStatusReportBase(
|
||||
"init",
|
||||
"aborted",
|
||||
startedAt,
|
||||
e.message
|
||||
)
|
||||
await sendStatusReport(
|
||||
await createStatusReportBase("init", "aborted", startedAt, e.message)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
@ -209,8 +218,8 @@ async function run() {
|
|||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
await actionsUtil.sendStatusReport(
|
||||
await actionsUtil.createStatusReportBase(
|
||||
await sendStatusReport(
|
||||
await createStatusReportBase(
|
||||
"init",
|
||||
"failure",
|
||||
startedAt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue