mirror of
https://github.com/github/codeql-action.git
synced 2026-01-03 05:00:04 +08:00
Merge branch 'main' into henrymercer/remove-legacy-tracing
This commit is contained in:
@@ -313,6 +313,8 @@ export type ActionStatus =
|
||||
export interface StatusReportBase {
|
||||
/** ID of the workflow run containing the action run. */
|
||||
workflow_run_id: number;
|
||||
/** Attempt number of the run containing the action run. */
|
||||
workflow_run_attempt: number;
|
||||
/** Workflow name. Converted to analysis_name further down the pipeline.. */
|
||||
workflow_name: string;
|
||||
/** Job name from the workflow. */
|
||||
@@ -410,6 +412,11 @@ export async function createStatusReportBase(
|
||||
if (workflowRunIDStr) {
|
||||
workflowRunID = parseInt(workflowRunIDStr, 10);
|
||||
}
|
||||
const workflowRunAttemptStr = process.env["GITHUB_RUN_ATTEMPT"];
|
||||
let workflowRunAttempt = -1;
|
||||
if (workflowRunAttemptStr) {
|
||||
workflowRunAttempt = parseInt(workflowRunAttemptStr, 10);
|
||||
}
|
||||
const workflowName = process.env["GITHUB_WORKFLOW"] || "";
|
||||
const jobName = process.env["GITHUB_JOB"] || "";
|
||||
const analysis_key = await getAnalysisKey();
|
||||
@@ -437,6 +444,7 @@ export async function createStatusReportBase(
|
||||
|
||||
const statusReport: StatusReportBase = {
|
||||
workflow_run_id: workflowRunID,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_name: workflowName,
|
||||
job_name: jobName,
|
||||
analysis_key,
|
||||
|
||||
@@ -7,13 +7,15 @@ import * as core from "@actions/core";
|
||||
|
||||
import * as analyzeActionPostHelper from "./analyze-action-post-helper";
|
||||
import * as debugArtifacts from "./debug-artifacts";
|
||||
import { wrapError } from "./util";
|
||||
|
||||
async function runWrapper() {
|
||||
try {
|
||||
await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact);
|
||||
} catch (error) {
|
||||
core.setFailed(`analyze post-action step failed: ${error}`);
|
||||
console.log(error);
|
||||
core.setFailed(
|
||||
`analyze post-action step failed: ${wrapError(error).message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import { getTotalCacheSize, uploadTrapCaches } from "./trap-caching";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import { UploadResult } from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
import { checkForTimeout } from "./util";
|
||||
import { checkForTimeout, wrapError } from "./util";
|
||||
|
||||
interface AnalysisStatusReport
|
||||
extends upload_lib.UploadStatusReport,
|
||||
@@ -311,9 +311,8 @@ async function run() {
|
||||
CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY,
|
||||
"true"
|
||||
);
|
||||
} catch (origError) {
|
||||
const error =
|
||||
origError instanceof Error ? origError : new Error(String(origError));
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
if (
|
||||
actionsUtil.getOptionalInput("expect-error") !== "true" ||
|
||||
hasBadExpectErrorInput()
|
||||
@@ -394,7 +393,7 @@ async function runWrapper() {
|
||||
try {
|
||||
await runPromise;
|
||||
} catch (error) {
|
||||
core.setFailed(`analyze action failed: ${error}`);
|
||||
core.setFailed(`analyze action failed: ${wrapError(error).message}`);
|
||||
}
|
||||
await checkForTimeout();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,11 @@ import * as configUtils from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { CODEQL_ACTION_DID_AUTOBUILD_GOLANG } from "./shared-environment";
|
||||
import { checkGitHubVersionInRange, initializeEnvironment } from "./util";
|
||||
import {
|
||||
checkGitHubVersionInRange,
|
||||
initializeEnvironment,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
|
||||
interface AutobuildStatusReport extends StatusReportBase {
|
||||
/** Comma-separated set of languages being auto-built. */
|
||||
@@ -89,18 +93,16 @@ async function run() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(
|
||||
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`
|
||||
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${error.message}`
|
||||
);
|
||||
console.log(error);
|
||||
await sendCompletedStatusReport(
|
||||
startedAt,
|
||||
languages ?? [],
|
||||
currentLanguage,
|
||||
error instanceof Error ? error : new Error(String(error))
|
||||
error
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -112,8 +114,7 @@ async function runWrapper() {
|
||||
try {
|
||||
await run();
|
||||
} catch (error) {
|
||||
core.setFailed(`autobuild action failed. ${error}`);
|
||||
console.log(error);
|
||||
core.setFailed(`autobuild action failed. ${wrapError(error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
getTrapCachingExtractorConfigArgsForLang,
|
||||
} from "./trap-caching";
|
||||
import * as util from "./util";
|
||||
import { wrapError } from "./util";
|
||||
|
||||
type Options = Array<string | number | boolean>;
|
||||
|
||||
@@ -287,12 +288,6 @@ export const CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE = "2.12.1";
|
||||
*/
|
||||
export const CODEQL_VERSION_INIT_WITH_QLCONFIG = "2.12.4";
|
||||
|
||||
/**
|
||||
* Versions 2.12.6+ of the CodeQL CLI fix a bug where duplicate notification objects could be produced,
|
||||
* leading to an invalid SARIF output.
|
||||
*/
|
||||
export const CODEQL_VERSION_DUPLICATE_NOTIFICATIONS_FIXED = "2.12.6";
|
||||
|
||||
/**
|
||||
* Set up CodeQL CLI access.
|
||||
*
|
||||
@@ -345,7 +340,7 @@ export async function setupCodeQL(
|
||||
toolsVersion,
|
||||
};
|
||||
} catch (e) {
|
||||
logger.error(e instanceof Error ? e : new Error(String(e)));
|
||||
logger.error(wrapError(e).message);
|
||||
throw new Error("Unable to download and extract CodeQL CLI");
|
||||
}
|
||||
}
|
||||
@@ -762,12 +757,8 @@ export async function getCodeQLForCmd(
|
||||
Feature.ExportDiagnosticsEnabled,
|
||||
this
|
||||
);
|
||||
const shouldWorkaroundInvalidNotifications =
|
||||
shouldExportDiagnostics &&
|
||||
!(await util.codeQlVersionAbove(
|
||||
this,
|
||||
CODEQL_VERSION_DUPLICATE_NOTIFICATIONS_FIXED
|
||||
));
|
||||
// Update this to take into account the CodeQL version when we have a version with the fix.
|
||||
const shouldWorkaroundInvalidNotifications = shouldExportDiagnostics;
|
||||
const codeqlOutputFile = shouldWorkaroundInvalidNotifications
|
||||
? path.join(config.tempDir, "codeql-intermediate-results.sarif")
|
||||
: sarifFile;
|
||||
@@ -917,11 +908,8 @@ export async function getCodeQLForCmd(
|
||||
tempDir: string,
|
||||
logger: Logger
|
||||
): Promise<void> {
|
||||
const shouldWorkaroundInvalidNotifications =
|
||||
!(await util.codeQlVersionAbove(
|
||||
this,
|
||||
CODEQL_VERSION_DUPLICATE_NOTIFICATIONS_FIXED
|
||||
));
|
||||
// Update this to take into account the CodeQL version when we have a version with the fix.
|
||||
const shouldWorkaroundInvalidNotifications = true;
|
||||
const codeqlOutputFile = shouldWorkaroundInvalidNotifications
|
||||
? path.join(tempDir, "codeql-intermediate-results.sarif")
|
||||
: sarifFile;
|
||||
|
||||
@@ -8,7 +8,12 @@ import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY } from "./shared-environment";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { getRequiredEnvParam, isInTestMode, parseMatrixInput } from "./util";
|
||||
import {
|
||||
getRequiredEnvParam,
|
||||
isInTestMode,
|
||||
parseMatrixInput,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
import {
|
||||
getCategoryInputOrThrow,
|
||||
getCheckoutPathInputOrThrow,
|
||||
@@ -28,11 +33,10 @@ export interface UploadFailedSarifResult extends uploadLib.UploadStatusReport {
|
||||
function createFailedUploadFailedSarifResult(
|
||||
error: unknown
|
||||
): UploadFailedSarifResult {
|
||||
const wrappedError = wrapError(error);
|
||||
return {
|
||||
upload_failed_run_error:
|
||||
error instanceof Error ? error.message : String(error),
|
||||
upload_failed_run_stack_trace:
|
||||
error instanceof Error ? error.stack : undefined,
|
||||
upload_failed_run_error: wrappedError.message,
|
||||
upload_failed_run_stack_trace: wrappedError.stack,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,11 @@ import { Features } from "./feature-flags";
|
||||
import * as initActionPostHelper from "./init-action-post-helper";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import { checkGitHubVersionInRange, getRequiredEnvParam } from "./util";
|
||||
import {
|
||||
checkGitHubVersionInRange,
|
||||
getRequiredEnvParam,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
|
||||
interface InitPostStatusReport
|
||||
extends StatusReportBase,
|
||||
@@ -54,17 +58,17 @@ async function runWrapper() {
|
||||
features,
|
||||
logger
|
||||
);
|
||||
} catch (e) {
|
||||
core.setFailed(e instanceof Error ? e.message : String(e));
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(error.message);
|
||||
|
||||
console.log(e);
|
||||
await sendStatusReport(
|
||||
await createStatusReportBase(
|
||||
"init-post",
|
||||
getActionsStatus(e),
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
String(e),
|
||||
e instanceof Error ? e.stack : undefined
|
||||
error.message,
|
||||
error.stack
|
||||
)
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as path from "path";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import {
|
||||
ActionStatus,
|
||||
createStatusReportBase,
|
||||
getActionsStatus,
|
||||
getActionVersion,
|
||||
@@ -40,6 +39,7 @@ import {
|
||||
GitHubVariant,
|
||||
initializeEnvironment,
|
||||
isHostedRunner,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
import { validateWorkflow } from "./workflow";
|
||||
|
||||
@@ -89,20 +89,22 @@ interface InitToolsDownloadFields {
|
||||
tools_feature_flags_valid?: boolean;
|
||||
}
|
||||
|
||||
async function sendInitStatusReport(
|
||||
actionStatus: ActionStatus,
|
||||
async function sendCompletedStatusReport(
|
||||
startedAt: Date,
|
||||
config: configUtils.Config | undefined,
|
||||
toolsDownloadDurationMs: number | undefined,
|
||||
toolsFeatureFlagsValid: boolean | undefined,
|
||||
toolsSource: ToolsSource,
|
||||
toolsVersion: string,
|
||||
logger: Logger
|
||||
logger: Logger,
|
||||
error?: Error
|
||||
) {
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
"init",
|
||||
actionStatus,
|
||||
startedAt
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
error?.message,
|
||||
error?.stack
|
||||
);
|
||||
|
||||
const workflowLanguages = getOptionalInput("languages");
|
||||
@@ -276,19 +278,24 @@ async function run() {
|
||||
) {
|
||||
try {
|
||||
await installPythonDeps(codeql, logger);
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
logger.warning(
|
||||
`${message} You can call this action with 'setup-python-dependencies: false' to disable this process`
|
||||
`${error.message} You can call this action with 'setup-python-dependencies: false' to disable this process`
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
const message = e instanceof Error ? e.message : String(e);
|
||||
core.setFailed(message);
|
||||
console.log(e);
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(error.message);
|
||||
await sendStatusReport(
|
||||
await createStatusReportBase("init", "aborted", startedAt, message)
|
||||
await createStatusReportBase(
|
||||
"init",
|
||||
"aborted",
|
||||
startedAt,
|
||||
error.message,
|
||||
error.stack
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -345,24 +352,22 @@ async function run() {
|
||||
}
|
||||
|
||||
core.setOutput("codeql-path", config.codeQLCmd);
|
||||
} catch (error) {
|
||||
core.setFailed(String(error));
|
||||
|
||||
console.log(error);
|
||||
await sendInitStatusReport(
|
||||
getActionsStatus(error),
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(error.message);
|
||||
await sendCompletedStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
toolsDownloadDurationMs,
|
||||
toolsFeatureFlagsValid,
|
||||
toolsSource,
|
||||
toolsVersion,
|
||||
logger
|
||||
logger,
|
||||
error
|
||||
);
|
||||
return;
|
||||
}
|
||||
await sendInitStatusReport(
|
||||
"success",
|
||||
await sendCompletedStatusReport(
|
||||
startedAt,
|
||||
config,
|
||||
toolsDownloadDurationMs,
|
||||
@@ -389,8 +394,7 @@ async function runWrapper() {
|
||||
try {
|
||||
await run();
|
||||
} catch (error) {
|
||||
core.setFailed(`init action failed: ${error}`);
|
||||
console.log(error);
|
||||
core.setFailed(`init action failed: ${wrapError(error).message}`);
|
||||
}
|
||||
await checkForTimeout();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as api from "./api-client";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import * as setupCodeql from "./setup-codeql";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment } from "./util";
|
||||
import { initializeEnvironment, wrapError } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
@@ -43,7 +43,7 @@ test("convert to semver", (t) => {
|
||||
);
|
||||
t.deepEqual(parsedVersion, expectedVersion);
|
||||
} catch (e) {
|
||||
t.fail(e instanceof Error ? e.message : String(e));
|
||||
t.fail(wrapError(e).message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ import { CodeQLDefaultVersionInfo } from "./feature-flags";
|
||||
import { ToolsSource } from "./init";
|
||||
import { Logger } from "./logging";
|
||||
import * as util from "./util";
|
||||
import { isGoodVersion } from "./util";
|
||||
import { isGoodVersion, wrapError } from "./util";
|
||||
|
||||
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
|
||||
@@ -145,7 +145,7 @@ export async function tryFindCliVersionDotcomOnly(
|
||||
} catch (e) {
|
||||
logger.debug(
|
||||
`Failed to find the CLI version for the CodeQL bundle tagged ${tagName}. ${
|
||||
e instanceof Error ? e.message : e
|
||||
wrapError(e).message
|
||||
}`
|
||||
);
|
||||
return undefined;
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
import * as safeWhich from "@chrisgavin/safe-which";
|
||||
|
||||
import { ErrorMatcher } from "./error-matcher";
|
||||
import { wrapError } from "./util";
|
||||
|
||||
export interface ReturnState {
|
||||
exitCode: number;
|
||||
@@ -81,7 +82,6 @@ export async function toolrunnerErrorCatcher(
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
const error = e instanceof Error ? e : new Error(String(e));
|
||||
throw error;
|
||||
throw wrapError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Logger } from "./logging";
|
||||
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
|
||||
import { CODEQL_WORKFLOW_STARTED_AT } from "./shared-environment";
|
||||
import * as util from "./util";
|
||||
import { SarifFile, SarifResult, SarifRun } from "./util";
|
||||
import { SarifFile, SarifResult, SarifRun, wrapError } from "./util";
|
||||
import * as workflow from "./workflow";
|
||||
|
||||
// Takes a list of paths to sarif files and combines them together,
|
||||
@@ -204,9 +204,7 @@ export function countResultsInSarif(sarif: string): number {
|
||||
parsedSarif = JSON.parse(sarif);
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Invalid SARIF. JSON syntax error: ${
|
||||
e instanceof Error ? e.message : String(e)
|
||||
}`
|
||||
`Invalid SARIF. JSON syntax error: ${wrapError(e).message}`
|
||||
);
|
||||
}
|
||||
if (!Array.isArray(parsedSarif.runs)) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
getRequiredEnvParam,
|
||||
initializeEnvironment,
|
||||
isInTestMode,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
|
||||
interface UploadSarifStatusReport
|
||||
@@ -66,9 +67,9 @@ async function run() {
|
||||
);
|
||||
}
|
||||
await sendSuccessStatusReport(startedAt, uploadResult.statusReport);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const stack = error instanceof Error ? error.stack : String(error);
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
const message = error.message;
|
||||
core.setFailed(message);
|
||||
console.log(error);
|
||||
await actionsUtil.sendStatusReport(
|
||||
@@ -77,7 +78,7 @@ async function run() {
|
||||
actionsUtil.getActionsStatus(error),
|
||||
startedAt,
|
||||
message,
|
||||
stack
|
||||
error.stack
|
||||
)
|
||||
);
|
||||
return;
|
||||
@@ -88,8 +89,9 @@ async function runWrapper() {
|
||||
try {
|
||||
await run();
|
||||
} catch (error) {
|
||||
core.setFailed(`codeql/upload-sarif action failed: ${error}`);
|
||||
console.log(error);
|
||||
core.setFailed(
|
||||
`codeql/upload-sarif action failed: ${wrapError(error).message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
src/util.ts
20
src/util.ts
@@ -113,10 +113,10 @@ export function getExtraOptionsEnvParam(): object {
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (e) {
|
||||
const message = e instanceof Error ? e.message : String(e);
|
||||
} catch (unwrappedError) {
|
||||
const error = wrapError(unwrappedError);
|
||||
throw new Error(
|
||||
`${varName} environment variable is set, but does not contain valid JSON: ${message}`
|
||||
`${varName} environment variable is set, but does not contain valid JSON: ${error.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -438,11 +438,11 @@ export function assertNever(value: never): never {
|
||||
* knowing what version of CodeQL we're running.
|
||||
*/
|
||||
export function initializeEnvironment(version: string) {
|
||||
core.exportVariable(EnvVar.FEATURE_MULTI_LANGUAGE, "false");
|
||||
core.exportVariable(EnvVar.FEATURE_SANDWICH, "false");
|
||||
core.exportVariable(EnvVar.FEATURE_SARIF_COMBINE, "true");
|
||||
core.exportVariable(EnvVar.FEATURE_WILL_UPLOAD, "true");
|
||||
core.exportVariable(EnvVar.VERSION, version);
|
||||
core.exportVariable(String(EnvVar.FEATURE_MULTI_LANGUAGE), "false");
|
||||
core.exportVariable(String(EnvVar.FEATURE_SANDWICH), "false");
|
||||
core.exportVariable(String(EnvVar.FEATURE_SARIF_COMBINE), "true");
|
||||
core.exportVariable(String(EnvVar.FEATURE_WILL_UPLOAD), "true");
|
||||
core.exportVariable(String(EnvVar.VERSION), version);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -892,3 +892,7 @@ export function fixInvalidNotificationsInFile(
|
||||
sarif = fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(outputPath, JSON.stringify(sarif));
|
||||
}
|
||||
|
||||
export function wrapError(error: unknown): Error {
|
||||
return error instanceof Error ? error : new Error(String(error));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user