Cleaning up comments around env vars

Also, move `getTemporaryDirectory` back to `actions-util`.
This commit is contained in:
Andrew Eisenberg
2021-06-03 11:18:25 -07:00
parent cc0733fd12
commit f60ef170b0
15 changed files with 101 additions and 88 deletions

View File

@@ -38,6 +38,13 @@ export function getOptionalInput(name: string): string | undefined {
return value.length > 0 ? value : undefined;
}
export function getTemporaryDirectory(): string {
const value = process.env["CODEQL_ACTION_TEMP"];
return value !== undefined && value !== ""
? value
: getRequiredEnvParam("RUNNER_TEMP");
}
export function getToolCacheDirectory(): string {
const value = process.env["CODEQL_ACTION_TOOL_CACHE"];
return value !== undefined && value !== ""

View File

@@ -67,7 +67,7 @@ async function run() {
return;
}
const logger = getActionsLogger();
config = await getConfig(util.getTemporaryDirectory(), logger);
config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?"

View File

@@ -2,6 +2,7 @@ import * as core from "@actions/core";
import {
createStatusReportBase,
getTemporaryDirectory,
sendStatusReport,
StatusReportBase,
} from "./actions-util";
@@ -9,7 +10,7 @@ import { determineAutobuildLanguage, runAutobuild } from "./autobuild";
import * as config_utils from "./config-utils";
import { Language } from "./languages";
import { getActionsLogger } from "./logging";
import { getTemporaryDirectory, initializeEnvironment, Mode } from "./util";
import { initializeEnvironment, Mode } from "./util";
// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");

View File

@@ -4,6 +4,7 @@ import {
createStatusReportBase,
getOptionalInput,
getRequiredInput,
getTemporaryDirectory,
getToolCacheDirectory,
sendStatusReport,
StatusReportBase,
@@ -23,7 +24,6 @@ import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
getRequiredEnvParam,
getTemporaryDirectory,
initializeEnvironment,
Mode,
checkGitHubVersionInRange,

View File

@@ -399,47 +399,57 @@ export enum Mode {
* and the action.
*/
enum EnvVar {
// either 'actions' or 'runner'
/**
* The mode of the codeql-action, either 'actions' or 'runner'.
*/
RUN_MODE = "CODEQL_ACTION_RUN_MODE",
// semver of this action
/**
* Semver of the codeql-action as specified in package.json.
*/
VERSION = "CODEQL_ACTION_VERSION",
// if set to a truthy value, then the action might combine SARIF
// output from several `interpret-results` runs for the same language
/**
* If set to a truthy value, then the codeql-action might combine SARIF
* output from several `interpret-results` runs for the same Language.
*/
FEATURE_SARIF_COMBINE = "CODEQL_ACTION_FEATURE_SARIF_COMBINE",
// if set to a truthy value, then the action will upload SARIF,
// not the CLI
/**
* If set to the "true" string, then the codeql-action will upload SARIF,
* not the cli.
*/
FEATURE_WILL_UPLOAD = "CODEQL_ACTION_FEATURE_WILL_UPLOAD",
// if set to a truthy value, then the action is using its
// own deprecated and non-standard way of scanning for multiple
// languages
/**
* If set to the "true" string, then the codeql-action is using its
* own deprecated and non-standard way of scanning for multiple
* languages.
*/
FEATURE_MULTI_LANGUAGE = "CODEQL_ACTION_FEATURE_MULTI_LANGUAGE",
// if set to a truthy value, then the action is using its
// own sandwiched workflow mechanism
/**
* If set to the "true" string, then the codeql-action is using its
* own sandwiched workflow mechanism
*/
FEATURE_SANDWICH = "CODEQL_ACTION_FEATURE_SANDWICH",
}
export function initializeEnvironment(mode: Mode, version: string) {
// avoid accessing actions core when in runner mode
if (mode === Mode.actions) {
core.exportVariable(EnvVar.RUN_MODE, mode);
core.exportVariable(EnvVar.VERSION, version);
core.exportVariable(EnvVar.FEATURE_SARIF_COMBINE, "true");
core.exportVariable(EnvVar.FEATURE_WILL_UPLOAD, "true");
core.exportVariable(EnvVar.FEATURE_MULTI_LANGUAGE, "true");
core.exportVariable(EnvVar.FEATURE_SANDWICH, "true");
} else {
process.env[EnvVar.RUN_MODE] = mode;
process.env[EnvVar.VERSION] = version;
process.env[EnvVar.FEATURE_SARIF_COMBINE] = "true";
process.env[EnvVar.FEATURE_WILL_UPLOAD] = "true";
process.env[EnvVar.FEATURE_MULTI_LANGUAGE] = "true";
process.env[EnvVar.FEATURE_SANDWICH] = "true";
}
const exportVar = (name: string, value: string) => {
if (mode === Mode.actions) {
core.exportVariable(name, value);
} else {
process.env[name] = value;
}
};
exportVar(EnvVar.RUN_MODE, mode);
exportVar(EnvVar.VERSION, version);
exportVar(EnvVar.FEATURE_SARIF_COMBINE, "true");
exportVar(EnvVar.FEATURE_WILL_UPLOAD, "true");
exportVar(EnvVar.FEATURE_MULTI_LANGUAGE, "true");
exportVar(EnvVar.FEATURE_SANDWICH, "true");
}
export function getMode(): Mode {
@@ -466,16 +476,5 @@ export function getRequiredEnvParam(paramName: string): string {
if (value === undefined || value.length === 0) {
throw new Error(`${paramName} environment variable must be set`);
}
if (process.env[EnvVar.RUN_MODE] === Mode.actions) {
core.debug(`${paramName}=${value}`);
}
return value;
}
export function getTemporaryDirectory(): string {
const value = process.env["CODEQL_ACTION_TEMP"];
return value !== undefined && value !== ""
? value
: getRequiredEnvParam("RUNNER_TEMP");
}