Add utility function to get testing environment
This commit is contained in:
parent
15bce5bb14
commit
f681ad69a7
9 changed files with 49 additions and 24 deletions
6
lib/status-report.js
generated
6
lib/status-report.js
generated
|
|
@ -149,10 +149,10 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi
|
|||
const runnerOs = (0, util_1.getRequiredEnvParam)("RUNNER_OS");
|
||||
const codeQlCliVersion = (0, util_1.getCachedCodeQlVersion)();
|
||||
const actionRef = process.env["GITHUB_ACTION_REF"] || "";
|
||||
const testingEnvironment = process.env[environment_1.EnvVar.TESTING_ENVIRONMENT] || "";
|
||||
const testingEnvironment = (0, util_1.getTestingEnvironment)();
|
||||
// re-export the testing environment variable so that it is available to subsequent steps,
|
||||
// even if it was only set for this step
|
||||
if (testingEnvironment !== "") {
|
||||
if (testingEnvironment) {
|
||||
core.exportVariable(environment_1.EnvVar.TESTING_ENVIRONMENT, testingEnvironment);
|
||||
}
|
||||
const isSteadyStateDefaultSetupRun = process.env["CODE_SCANNING_IS_STEADY_STATE_DEFAULT_SETUP"] === "true";
|
||||
|
|
@ -173,7 +173,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi
|
|||
started_at: workflowStartedAt,
|
||||
status,
|
||||
steady_state_default_setup: isSteadyStateDefaultSetupRun,
|
||||
testing_environment: testingEnvironment,
|
||||
testing_environment: testingEnvironment || "",
|
||||
workflow_name: workflowName,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_run_id: workflowRunID,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
19
lib/util.js
generated
19
lib/util.js
generated
|
|
@ -62,6 +62,7 @@ exports.bundleDb = bundleDb;
|
|||
exports.delay = delay;
|
||||
exports.isGoodVersion = isGoodVersion;
|
||||
exports.isInTestMode = isInTestMode;
|
||||
exports.getTestingEnvironment = getTestingEnvironment;
|
||||
exports.doesDirectoryExist = doesDirectoryExist;
|
||||
exports.listFolder = listFolder;
|
||||
exports.tryGetFolderBytes = tryGetFolderBytes;
|
||||
|
|
@ -577,15 +578,27 @@ async function delay(milliseconds, opts) {
|
|||
function isGoodVersion(versionSpec) {
|
||||
return !BROKEN_VERSIONS.includes(versionSpec);
|
||||
}
|
||||
/*
|
||||
* Returns whether we are in test mode.
|
||||
/**
|
||||
* Returns whether we are in test mode. This is used by CodeQL Action PR checks.
|
||||
*
|
||||
* In test mode, we don't upload SARIF results or status reports to the GitHub API.
|
||||
*/
|
||||
function isInTestMode() {
|
||||
return process.env[environment_1.EnvVar.TEST_MODE] === "true";
|
||||
}
|
||||
/*
|
||||
/**
|
||||
* Get the testing environment.
|
||||
*
|
||||
* This is set if the CodeQL Action is running in a non-production environment.
|
||||
*/
|
||||
function getTestingEnvironment() {
|
||||
const testingEnvironment = process.env[environment_1.EnvVar.TESTING_ENVIRONMENT] || "";
|
||||
if (testingEnvironment === "") {
|
||||
return undefined;
|
||||
}
|
||||
return testingEnvironment;
|
||||
}
|
||||
/**
|
||||
* Returns whether the path in the argument represents an existing directory.
|
||||
*/
|
||||
function doesDirectoryExist(dirPath) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
4
lib/workflow.js
generated
4
lib/workflow.js
generated
|
|
@ -51,7 +51,6 @@ const zlib_1 = __importDefault(require("zlib"));
|
|||
const core = __importStar(require("@actions/core"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const environment_1 = require("./environment");
|
||||
const util_1 = require("./util");
|
||||
function toCodedErrors(errors) {
|
||||
return Object.entries(errors).reduce((acc, [code, message]) => {
|
||||
|
|
@ -274,8 +273,7 @@ function getInputOrThrow(workflow, jobName, actionName, inputName, matrixVars) {
|
|||
* This allows us to test workflow parsing functionality as a CodeQL Action PR check.
|
||||
*/
|
||||
function getAnalyzeActionName() {
|
||||
if ((0, util_1.isInTestMode)() ||
|
||||
process.env[environment_1.EnvVar.TESTING_ENVIRONMENT] === "codeql-action-pr-checks") {
|
||||
if ((0, util_1.isInTestMode)() || (0, util_1.getTestingEnvironment)() === "codeql-action-pr-checks") {
|
||||
return "./analyze";
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -29,6 +29,7 @@ import {
|
|||
assertNever,
|
||||
BuildMode,
|
||||
getErrorMessage,
|
||||
getTestingEnvironment,
|
||||
} from "./util";
|
||||
|
||||
export enum ActionName {
|
||||
|
|
@ -277,10 +278,10 @@ export async function createStatusReportBase(
|
|||
const runnerOs = getRequiredEnvParam("RUNNER_OS");
|
||||
const codeQlCliVersion = getCachedCodeQlVersion();
|
||||
const actionRef = process.env["GITHUB_ACTION_REF"] || "";
|
||||
const testingEnvironment = process.env[EnvVar.TESTING_ENVIRONMENT] || "";
|
||||
const testingEnvironment = getTestingEnvironment();
|
||||
// re-export the testing environment variable so that it is available to subsequent steps,
|
||||
// even if it was only set for this step
|
||||
if (testingEnvironment !== "") {
|
||||
if (testingEnvironment) {
|
||||
core.exportVariable(EnvVar.TESTING_ENVIRONMENT, testingEnvironment);
|
||||
}
|
||||
const isSteadyStateDefaultSetupRun =
|
||||
|
|
@ -303,7 +304,7 @@ export async function createStatusReportBase(
|
|||
started_at: workflowStartedAt,
|
||||
status,
|
||||
steady_state_default_setup: isSteadyStateDefaultSetupRun,
|
||||
testing_environment: testingEnvironment,
|
||||
testing_environment: testingEnvironment || "",
|
||||
workflow_name: workflowName,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_run_id: workflowRunID,
|
||||
|
|
|
|||
19
src/util.ts
19
src/util.ts
|
|
@ -750,8 +750,8 @@ export function isGoodVersion(versionSpec: string) {
|
|||
return !BROKEN_VERSIONS.includes(versionSpec);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns whether we are in test mode.
|
||||
/**
|
||||
* Returns whether we are in test mode. This is used by CodeQL Action PR checks.
|
||||
*
|
||||
* In test mode, we don't upload SARIF results or status reports to the GitHub API.
|
||||
*/
|
||||
|
|
@ -759,7 +759,20 @@ export function isInTestMode(): boolean {
|
|||
return process.env[EnvVar.TEST_MODE] === "true";
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Get the testing environment.
|
||||
*
|
||||
* This is set if the CodeQL Action is running in a non-production environment.
|
||||
*/
|
||||
export function getTestingEnvironment(): string | undefined {
|
||||
const testingEnvironment = process.env[EnvVar.TESTING_ENVIRONMENT] || "";
|
||||
if (testingEnvironment === "") {
|
||||
return undefined;
|
||||
}
|
||||
return testingEnvironment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the path in the argument represents an existing directory.
|
||||
*/
|
||||
export function doesDirectoryExist(dirPath: string): boolean {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,12 @@ import * as yaml from "js-yaml";
|
|||
|
||||
import * as api from "./api-client";
|
||||
import { CodeQL } from "./codeql";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Logger } from "./logging";
|
||||
import { getRequiredEnvParam, isInTestMode } from "./util";
|
||||
import {
|
||||
getRequiredEnvParam,
|
||||
getTestingEnvironment,
|
||||
isInTestMode,
|
||||
} from "./util";
|
||||
|
||||
export interface WorkflowJobStep {
|
||||
name?: string;
|
||||
|
|
@ -358,10 +361,7 @@ function getInputOrThrow(
|
|||
* This allows us to test workflow parsing functionality as a CodeQL Action PR check.
|
||||
*/
|
||||
function getAnalyzeActionName() {
|
||||
if (
|
||||
isInTestMode() ||
|
||||
process.env[EnvVar.TESTING_ENVIRONMENT] === "codeql-action-pr-checks"
|
||||
) {
|
||||
if (isInTestMode() || getTestingEnvironment() === "codeql-action-pr-checks") {
|
||||
return "./analyze";
|
||||
} else {
|
||||
return "github/codeql-action/analyze";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue