diff --git a/.github/workflows/python312-windows.yml b/.github/workflows/python312-windows.yml index 77bf8155fd..95bd747408 100644 --- a/.github/workflows/python312-windows.yml +++ b/.github/workflows/python312-windows.yml @@ -38,4 +38,5 @@ jobs: - name: Analyze uses: ./../action/analyze with: + upload: false upload-database: false diff --git a/lib/init-action-post-helper.js b/lib/init-action-post-helper.js index 89fbdff198..168fe55145 100644 --- a/lib/init-action-post-helper.js +++ b/lib/init-action-post-helper.js @@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.run = exports.tryUploadSarifIfRunFailed = void 0; const core = __importStar(require("@actions/core")); const actionsUtil = __importStar(require("./actions-util")); +const api_client_1 = require("./api-client"); const codeql_1 = require("./codeql"); const config_utils_1 = require("./config-utils"); const environment_1 = require("./environment"); @@ -76,7 +77,9 @@ async function maybeUploadFailedSarif(config, repositoryNwo, features, logger) { core.info(`Uploading failed SARIF file ${sarifFile}`); const uploadResult = await uploadLib.uploadFromActions(sarifFile, checkoutPath, category, logger, { considerInvalidRequestUserError: false }); await uploadLib.waitForProcessing(repositoryNwo, uploadResult.sarifID, logger, { isUnsuccessfulExecution: true }); - return uploadResult?.statusReport ?? {}; + return uploadResult + ? { ...uploadResult.statusReport, sarifID: uploadResult.sarifID } + : {}; } async function tryUploadSarifIfRunFailed(config, repositoryNwo, features, logger) { if (process.env[environment_1.EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY] !== "true") { @@ -114,6 +117,9 @@ async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, p throw new Error("Expected to upload a failed SARIF file for this CodeQL code scanning run, " + `but the result was instead ${error}.`); } + if (process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true") { + await removeUploadedSarif(uploadFailedSarifResult); + } // Upload appropriate Actions artifacts for debugging if (config.debugMode) { core.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts..."); @@ -124,4 +130,36 @@ async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, p return uploadFailedSarifResult; } exports.run = run; +async function removeUploadedSarif(uploadFailedSarifResult) { + const sarifID = uploadFailedSarifResult.sarifID; + if (sarifID) { + core.info(`Uploaded failed SARIF file with ID ${sarifID}. Because this is a test, the analysis associated with it will now be deleted.`); + const client = (0, api_client_1.getApiClient)(); + try { + // Get the analysis associated with the uploaded sarif + const analysisInfo = await client.request("GET /repos/:owner/:repo/code-scanning/analyses?sarif_id:sarif_id", { + owner: "github", + repo: "codeql-action", + sarif_id: sarifID, + }); + // Delete the analysis. + for (const analysis of analysisInfo.data) { + core.info(`Deleting analysis ${analysis.id}`); + await client.request("DELETE /repos/:owner/:repo/code-scanning/analyses/:analysis_id", { + owner: "github", + repo: "codeql-action", + analysis_id: analysis.id, + }); + } + } + catch (e) { + // Fail the test if we can't delete the analysis. + core.error("Failed to delete uploaded SARIF analysis."); + throw e; + } + } + else { + core.warning("Could not delete uploaded SARIF analysis because no sarifID was returned."); + } +} //# sourceMappingURL=init-action-post-helper.js.map \ No newline at end of file diff --git a/lib/init-action-post-helper.js.map b/lib/init-action-post-helper.js.map index 7bc95cf65f..0310c60f7c 100644 --- a/lib/init-action-post-helper.js.map +++ b/lib/init-action-post-helper.js.map @@ -1 +1 @@ -{"version":3,"file":"init-action-post-helper.js","sourceRoot":"","sources":["../src/init-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,4DAA8C;AAC9C,qCAAyE;AACzE,iDAAmD;AACnD,+CAAuC;AACvC,mDAA6D;AAG7D,wDAA0C;AAC1C,iCAMgB;AAChB,yCAKoB;AAWpB,SAAS,mCAAmC,CAC1C,KAAc;IAEd,MAAM,YAAY,GAAG,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC;IACtC,OAAO;QACL,uBAAuB,EAAE,YAAY,CAAC,OAAO;QAC7C,6BAA6B,EAAE,YAAY,CAAC,KAAK;KAClD,CAAC;AACJ,CAAC;AAED;;;G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,UAAU,GAAG,CACvB,iCAA2C,EAC3C,uBAAiC,EACjC,cAAwB,EACxB,aAA4B,EAC5B,QAA2B,EAC3B,MAAc;IAEd,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,MAAM,CAAC,OAAO,CACZ,iGAAiG,CAClG,CAAC;QACF,OAAO;KACR;IAED,MAAM,uBAAuB,GAAG,MAAM,yBAAyB,CAC7D,MAAM,EACN,aAAa,EACb,QAAQ,EACR,MAAM,CACP,CAAC;IAEF,IAAI,uBAAuB,CAAC,iCAAiC,EAAE;QAC7D,MAAM,CAAC,KAAK,CACV,8EAA8E;YAC5E,GAAG,uBAAuB,CAAC,iCAAiC,GAAG,CAClE,CAAC;KACH;IACD,8FAA8F;IAC9F,iCAAiC;IACjC,IACE,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,KAAK,MAAM;QAClE,CAAC,uBAAuB,CAAC,qBAAqB,EAC9C;QACA,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;QACtD,MAAM,IAAI,KAAK,CACb,4EAA4E;YAC1E,8BAA8B,KAAK,GAAG,CACzC,CAAC;KACH;IAED,qDAAqD;IACrD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,IAAI,CAAC,IAAI,CACP,mGAAmG,CACpG,CAAC;QACF,MAAM,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;KAC9B;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAtDD,kBAsDC"} \ No newline at end of file +{"version":3,"file":"init-action-post-helper.js","sourceRoot":"","sources":["../src/init-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;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AiD;YACjD,IAAI,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;YACxD,MAAM,CAAC,CAAC;SACT;KACF;SAAM;QACL,IAAI,CAAC,OAAO,CACV,2EAA2E,CAC5E,CAAC;KACH;AACH,CAAC"} \ No newline at end of file diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 510adac123..ba6fe5a95c 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -1,6 +1,7 @@ import * as core from "@actions/core"; import * as actionsUtil from "./actions-util"; +import { getApiClient } from "./api-client"; import { CODEQL_VERSION_EXPORT_FAILED_SARIF, getCodeQL } from "./codeql"; import { Config, getConfig } from "./config-utils"; import { EnvVar } from "./environment"; @@ -29,6 +30,9 @@ export interface UploadFailedSarifResult extends uploadLib.UploadStatusReport { upload_failed_run_stack_trace?: string; /** Reason why we did not upload a SARIF payload with `executionSuccessful: false`. */ upload_failed_run_skipped_because?: string; + + /** The internal ID of SARIF analysis. */ + sarifID?: string; } function createFailedUploadFailedSarifResult( @@ -107,7 +111,9 @@ async function maybeUploadFailedSarif( logger, { isUnsuccessfulExecution: true }, ); - return uploadResult?.statusReport ?? {}; + return uploadResult + ? { ...uploadResult.statusReport, sarifID: uploadResult.sarifID } + : {}; } export async function tryUploadSarifIfRunFailed( @@ -180,6 +186,10 @@ export async function run( ); } + if (process.env["CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF"] === "true") { + await removeUploadedSarif(uploadFailedSarifResult); + } + // Upload appropriate Actions artifacts for debugging if (config.debugMode) { core.info( @@ -193,3 +203,48 @@ export async function run( return uploadFailedSarifResult; } + +async function removeUploadedSarif( + uploadFailedSarifResult: UploadFailedSarifResult, +) { + const sarifID = uploadFailedSarifResult.sarifID; + if (sarifID) { + core.info( + `Uploaded failed SARIF file with ID ${sarifID}. Because this is a test, the analysis associated with it will now be deleted.`, + ); + const client = getApiClient(); + + try { + // Get the analysis associated with the uploaded sarif + const analysisInfo = await client.request( + "GET /repos/:owner/:repo/code-scanning/analyses?sarif_id:sarif_id", + { + owner: "github", + repo: "codeql-action", + sarif_id: sarifID, + }, + ); + + // Delete the analysis. + for (const analysis of analysisInfo.data) { + core.info(`Deleting analysis ${analysis.id}`); + await client.request( + "DELETE /repos/:owner/:repo/code-scanning/analyses/:analysis_id", + { + owner: "github", + repo: "codeql-action", + analysis_id: analysis.id, + }, + ); + } + } catch (e) { + // Fail the test if we can't delete the analysis. + core.error("Failed to delete uploaded SARIF analysis."); + throw e; + } + } else { + core.warning( + "Could not delete uploaded SARIF analysis because no sarifID was returned.", + ); + } +}