mirror of
https://github.com/github/codeql-action.git
synced 2026-01-01 04:00:24 +08:00
Merge pull request #3180 from github/redsun82/skip-sarif-upload
Introduce `CODEQL_ACTION_SKIP_SARIF_UPLOAD`
This commit is contained in:
@@ -128,4 +128,10 @@ export enum EnvVar {
|
||||
* whether the upload is disabled. This is intended for testing and debugging purposes.
|
||||
*/
|
||||
SARIF_DUMP_DIR = "CODEQL_ACTION_SARIF_DUMP_DIR",
|
||||
|
||||
/**
|
||||
* Whether to skip uploading SARIF results to GitHub. Intended for testing purposes.
|
||||
* This setting is more specific than `CODEQL_ACTION_TEST_MODE`, which implies this option.
|
||||
*/
|
||||
SKIP_SARIF_UPLOAD = "CODEQL_ACTION_SKIP_SARIF_UPLOAD",
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
delay,
|
||||
getErrorMessage,
|
||||
getRequiredEnvParam,
|
||||
isInTestMode,
|
||||
parseMatrixInput,
|
||||
shouldSkipSarifUpload,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
import {
|
||||
@@ -81,7 +81,7 @@ async function maybeUploadFailedSarif(
|
||||
!["always", "failure-only"].includes(
|
||||
actionsUtil.getUploadValue(shouldUpload),
|
||||
) ||
|
||||
isInTestMode()
|
||||
shouldSkipSarifUpload()
|
||||
) {
|
||||
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
|
||||
}
|
||||
|
||||
@@ -356,18 +356,17 @@ async function uploadPayload(
|
||||
): Promise<string> {
|
||||
logger.info("Uploading results");
|
||||
|
||||
// If in test mode we don't want to upload the results
|
||||
if (util.isInTestMode()) {
|
||||
if (util.shouldSkipSarifUpload()) {
|
||||
const payloadSaveFile = path.join(
|
||||
actionsUtil.getTemporaryDirectory(),
|
||||
`payload-${analysis.kind}.json`,
|
||||
);
|
||||
logger.info(
|
||||
`In test mode. Results are not uploaded. Saving to ${payloadSaveFile}`,
|
||||
`SARIF upload disabled by an environment variable. Saving to ${payloadSaveFile}`,
|
||||
);
|
||||
logger.info(`Payload: ${JSON.stringify(payload, null, 2)}`);
|
||||
fs.writeFileSync(payloadSaveFile, JSON.stringify(payload, null, 2));
|
||||
return "test-mode-sarif-id";
|
||||
return "dummy-sarif-id";
|
||||
}
|
||||
|
||||
const client = api.getApiClient();
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
checkDiskUsage,
|
||||
getErrorMessage,
|
||||
initializeEnvironment,
|
||||
isInTestMode,
|
||||
shouldSkipSarifUpload,
|
||||
wrapError,
|
||||
} from "./util";
|
||||
|
||||
@@ -113,8 +113,10 @@ async function run() {
|
||||
core.setOutput("sarif-ids", JSON.stringify(uploadResults));
|
||||
|
||||
// We don't upload results in test mode, so don't wait for processing
|
||||
if (isInTestMode()) {
|
||||
core.debug("In test mode. Waiting for processing is disabled.");
|
||||
if (shouldSkipSarifUpload()) {
|
||||
core.debug(
|
||||
"SARIF upload disabled by an environment variable. Waiting for processing is disabled.",
|
||||
);
|
||||
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
|
||||
if (codeScanningResult !== undefined) {
|
||||
await upload_lib.waitForProcessing(
|
||||
|
||||
@@ -764,12 +764,19 @@ export function isGoodVersion(versionSpec: string) {
|
||||
/**
|
||||
* 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.
|
||||
* In test mode, we skip several uploads (SARIF results, status reports, DBs, ...).
|
||||
*/
|
||||
export function isInTestMode(): boolean {
|
||||
return process.env[EnvVar.TEST_MODE] === "true";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether we specifically want to skip uploading SARIF files.
|
||||
*/
|
||||
export function shouldSkipSarifUpload(): boolean {
|
||||
return isInTestMode() || process.env[EnvVar.SKIP_SARIF_UPLOAD] === "true";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the testing environment.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user