Add telemetry for uploading failed runs
This commit is contained in:
parent
896079047b
commit
e67ad6aaed
8 changed files with 130 additions and 26 deletions
|
|
@ -16,17 +16,29 @@ import {
|
|||
getWorkflow,
|
||||
} from "./workflow";
|
||||
|
||||
export interface UploadFailedSarifResult {
|
||||
/** Size in bytes of the unzipped SARIF payload uploaded for the failed run. */
|
||||
upload_failed_run_raw_upload_size_bytes?: number;
|
||||
/** Size in bytes of actual SARIF payload uploaded for the failed run. */
|
||||
upload_failed_run_zipped_upload_size_bytes?: number;
|
||||
|
||||
/** Error encountered during uploading the failed run. */
|
||||
upload_failed_run_error?: string;
|
||||
/** Reason why we did not upload a SARIF payload with `executionSuccessful: false`. */
|
||||
upload_failed_run_skipped_because?: string;
|
||||
}
|
||||
|
||||
export async function uploadFailedSarif(
|
||||
config: Config,
|
||||
repositoryNwo: RepositoryNwo,
|
||||
featureEnablement: FeatureEnablement,
|
||||
logger: Logger
|
||||
) {
|
||||
): Promise<UploadFailedSarifResult> {
|
||||
if (!config.codeQLCmd) {
|
||||
logger.warning(
|
||||
"CodeQL command not found. Unable to upload failed SARIF file."
|
||||
);
|
||||
return;
|
||||
return { upload_failed_run_skipped_because: "CodeQL command not found" };
|
||||
}
|
||||
const codeql = await getCodeQL(config.codeQLCmd);
|
||||
if (
|
||||
|
|
@ -36,7 +48,7 @@ export async function uploadFailedSarif(
|
|||
))
|
||||
) {
|
||||
logger.debug("Uploading failed SARIF is disabled.");
|
||||
return;
|
||||
return { upload_failed_run_skipped_because: "Feature disabled" };
|
||||
}
|
||||
const workflow = await getWorkflow();
|
||||
const jobName = getRequiredEnvParam("GITHUB_JOB");
|
||||
|
|
@ -48,7 +60,7 @@ export async function uploadFailedSarif(
|
|||
logger.debug(
|
||||
"Won't upload a failed SARIF file since SARIF upload is disabled."
|
||||
);
|
||||
return;
|
||||
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
|
||||
}
|
||||
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
|
||||
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
|
||||
|
|
@ -69,6 +81,12 @@ export async function uploadFailedSarif(
|
|||
logger,
|
||||
{ isUnsuccessfulExecution: true }
|
||||
);
|
||||
return {
|
||||
upload_failed_run_raw_upload_size_bytes:
|
||||
uploadResult?.statusReport?.raw_upload_size_bytes,
|
||||
upload_failed_run_zipped_upload_size_bytes:
|
||||
uploadResult?.statusReport?.zipped_upload_size_bytes,
|
||||
};
|
||||
}
|
||||
|
||||
export async function run(
|
||||
|
|
@ -91,9 +109,16 @@ export async function run(
|
|||
const expectFailedSarifUpload =
|
||||
process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true";
|
||||
|
||||
let uploadFailedSarifResult: UploadFailedSarifResult;
|
||||
|
||||
if (process.env[CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF] !== "true") {
|
||||
try {
|
||||
await uploadFailedSarif(config, repositoryNwo, featureEnablement, logger);
|
||||
uploadFailedSarifResult = await uploadFailedSarif(
|
||||
config,
|
||||
repositoryNwo,
|
||||
featureEnablement,
|
||||
logger
|
||||
);
|
||||
} catch (e) {
|
||||
if (expectFailedSarifUpload) {
|
||||
throw new Error(
|
||||
|
|
@ -104,11 +129,18 @@ export async function run(
|
|||
logger.info(
|
||||
`Failed to upload a SARIF file for the failed run. Error: ${e}`
|
||||
);
|
||||
uploadFailedSarifResult = {
|
||||
upload_failed_run_error: e instanceof Error ? e.message : String(e),
|
||||
};
|
||||
}
|
||||
} else if (expectFailedSarifUpload) {
|
||||
throw new Error(
|
||||
"Expected to upload a SARIF file for the failed run, but didn't."
|
||||
);
|
||||
} else {
|
||||
uploadFailedSarifResult = {
|
||||
upload_failed_run_skipped_because: "SARIF file already uploaded",
|
||||
};
|
||||
}
|
||||
|
||||
// Upload appropriate Actions artifacts for debugging
|
||||
|
|
@ -121,4 +153,6 @@ export async function run(
|
|||
|
||||
await printDebugLogs(config);
|
||||
}
|
||||
|
||||
return uploadFailedSarifResult;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue