mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 14:40:10 +08:00
Check for successful completion rather than SARIF upload
This doesn’t affect the overall behaviour, but means we can short-circuit slightly more quickly when `analyze` is passed `upload: false`.
This commit is contained in:
@@ -24,7 +24,7 @@ import { Features } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import { CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF } from "./shared-environment";
|
||||
import { CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY } from "./shared-environment";
|
||||
import { getTotalCacheSize, uploadTrapCaches } from "./trap-caching";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import { UploadResult } from "./upload-lib";
|
||||
@@ -279,7 +279,6 @@ async function run() {
|
||||
logger
|
||||
);
|
||||
core.setOutput("sarif-id", uploadResult.sarifID);
|
||||
core.exportVariable(CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF, "true");
|
||||
} else {
|
||||
logger.info("Not uploading results");
|
||||
}
|
||||
@@ -312,6 +311,10 @@ async function run() {
|
||||
`expect-error input was set to true but no error was thrown.`
|
||||
);
|
||||
}
|
||||
core.exportVariable(
|
||||
CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY,
|
||||
"true"
|
||||
);
|
||||
} catch (origError) {
|
||||
const error =
|
||||
origError instanceof Error ? origError : new Error(String(origError));
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Config, getConfig } from "./config-utils";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF } from "./shared-environment";
|
||||
import { CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY } from "./shared-environment";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { getRequiredEnvParam, isInTestMode, parseMatrixInput } from "./util";
|
||||
import {
|
||||
@@ -98,11 +98,11 @@ export async function uploadSarifIfRunFailed(
|
||||
featureEnablement: FeatureEnablement,
|
||||
logger: Logger
|
||||
): Promise<UploadFailedSarifResult> {
|
||||
// Environment variable used to integration test uploading a SARIF file for failed runs
|
||||
// This environment variable is used to integration test uploading a SARIF file for failed runs
|
||||
const expectFailedSarifUpload =
|
||||
process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true";
|
||||
|
||||
if (process.env[CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") {
|
||||
if (process.env[CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY] !== "true") {
|
||||
try {
|
||||
return await uploadFailedSarif(
|
||||
config,
|
||||
@@ -113,22 +113,23 @@ export async function uploadSarifIfRunFailed(
|
||||
} catch (e) {
|
||||
if (expectFailedSarifUpload) {
|
||||
throw new Error(
|
||||
"Expected to upload a SARIF file for the failed run, but encountered " +
|
||||
"Expected to upload a SARIF file for this failed CodeQL code scanning run, but encountered " +
|
||||
`the following error: ${e}`
|
||||
);
|
||||
}
|
||||
logger.info(
|
||||
`Failed to upload a SARIF file for the failed run. Error: ${e}`
|
||||
`Failed to upload a SARIF file for this failed CodeQL code scanning run. ${e}`
|
||||
);
|
||||
return createFailedUploadFailedSarifResult(e);
|
||||
}
|
||||
} else if (expectFailedSarifUpload) {
|
||||
throw new Error(
|
||||
"Expected to upload a SARIF file for the failed run, but didn't."
|
||||
"Expected to upload a SARIF file for this failed CodeQL code scanning run, but didn't."
|
||||
);
|
||||
} else {
|
||||
return {
|
||||
upload_failed_run_skipped_because: "SARIF file already uploaded",
|
||||
upload_failed_run_skipped_because:
|
||||
"Analyze Action completed successfully",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* This environment variable is set to true when the `analyze` Action
|
||||
* successfully uploads a SARIF file. It does NOT indicate whether the
|
||||
* SARIF file was processed successfully.
|
||||
* completes successfully.
|
||||
*/
|
||||
export const CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF =
|
||||
"CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF";
|
||||
export const CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY =
|
||||
"CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY";
|
||||
|
||||
export const CODEQL_ACTION_TESTING_ENVIRONMENT =
|
||||
"CODEQL_ACTION_TESTING_ENVIRONMENT";
|
||||
|
||||
Reference in New Issue
Block a user