mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Bump artifact dependencies if CODEQL_ACTION_ARTIFACT_V2_UPGRADE enabled (#2482)
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com> Co-authored-by: Henry Mercer <henrymercer@github.com>
This commit is contained in:
47
lib/debug-artifacts.js
generated
47
lib/debug-artifacts.js
generated
@@ -30,9 +30,11 @@ exports.sanitizeArtifactName = sanitizeArtifactName;
|
||||
exports.uploadCombinedSarifArtifacts = uploadCombinedSarifArtifacts;
|
||||
exports.tryUploadAllAvailableDebugArtifacts = tryUploadAllAvailableDebugArtifacts;
|
||||
exports.uploadDebugArtifacts = uploadDebugArtifacts;
|
||||
exports.getArtifactUploaderClient = getArtifactUploaderClient;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const artifact = __importStar(require("@actions/artifact"));
|
||||
const artifactLegacy = __importStar(require("@actions/artifact-legacy"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const adm_zip_1 = __importDefault(require("adm-zip"));
|
||||
const del_1 = __importDefault(require("del"));
|
||||
@@ -40,6 +42,7 @@ const actions_util_1 = require("./actions-util");
|
||||
const analyze_1 = require("./analyze");
|
||||
const codeql_1 = require("./codeql");
|
||||
const environment_1 = require("./environment");
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const logging_1 = require("./logging");
|
||||
const util_1 = require("./util");
|
||||
function sanitizeArtifactName(name) {
|
||||
@@ -49,7 +52,7 @@ function sanitizeArtifactName(name) {
|
||||
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
||||
* environment variable is set
|
||||
*/
|
||||
async function uploadCombinedSarifArtifacts(logger) {
|
||||
async function uploadCombinedSarifArtifacts(logger, gitHubVariant, features) {
|
||||
const tempDir = (0, actions_util_1.getTemporaryDirectory)();
|
||||
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
||||
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
||||
@@ -68,7 +71,7 @@ async function uploadCombinedSarifArtifacts(logger) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
await uploadDebugArtifacts(toUpload, baseTempDir, "combined-sarif-artifacts");
|
||||
await uploadDebugArtifacts(logger, toUpload, baseTempDir, "combined-sarif-artifacts", gitHubVariant, features);
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
@@ -128,7 +131,7 @@ async function tryBundleDatabase(config, language, logger) {
|
||||
*
|
||||
* Logs and suppresses any errors that occur.
|
||||
*/
|
||||
async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
||||
async function tryUploadAllAvailableDebugArtifacts(config, logger, features) {
|
||||
const filesToUpload = [];
|
||||
try {
|
||||
for (const language of config.languages) {
|
||||
@@ -168,13 +171,13 @@ async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await (0, logging_1.withGroup)("Uploading debug artifacts", async () => uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName));
|
||||
await (0, logging_1.withGroup)("Uploading debug artifacts", async () => uploadDebugArtifacts(logger, filesToUpload, config.dbLocation, config.debugArtifactName, config.gitHubVersion.type, features));
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
}
|
||||
}
|
||||
async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
|
||||
async function uploadDebugArtifacts(logger, toUpload, rootDir, artifactName, ghVariant, features) {
|
||||
if (toUpload.length === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -189,11 +192,35 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
|
||||
core.info("Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input.");
|
||||
}
|
||||
}
|
||||
await artifact.create().uploadArtifact(sanitizeArtifactName(`${artifactName}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir), {
|
||||
continueOnError: true,
|
||||
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
||||
retentionDays: 7,
|
||||
});
|
||||
const artifactUploader = await getArtifactUploaderClient(logger, ghVariant, features);
|
||||
try {
|
||||
await artifactUploader.uploadArtifact(sanitizeArtifactName(`${artifactName}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir), {
|
||||
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
||||
retentionDays: 7,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
// A failure to upload debug artifacts should not fail the entire action.
|
||||
core.warning(`Failed to upload debug artifacts: ${e}`);
|
||||
}
|
||||
}
|
||||
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
|
||||
// until it is supported. We also use the legacy version of the client if the feature flag is disabled.
|
||||
// The feature flag is named `ArtifactV4Upgrade` to reduce customer confusion; customers are primarily affected by
|
||||
// `actions/download-artifact`, whose upgrade to v4 must be accompanied by the `@actions/artifact@v2` upgrade.
|
||||
async function getArtifactUploaderClient(logger, ghVariant, features) {
|
||||
if (ghVariant === util_1.GitHubVariant.GHES) {
|
||||
logger.info("Debug artifacts can be consumed with `actions/download-artifact@v3` because the `v4` version is not yet compatible on GHES.");
|
||||
return artifactLegacy.create();
|
||||
}
|
||||
else if (!(await features.getValue(feature_flags_1.Feature.ArtifactV4Upgrade))) {
|
||||
logger.info("Debug artifacts can be consumed with `actions/download-artifact@v3`. To use the `actions/download-artifact@v4`, set the `CODEQL_ACTION_ARTIFACT_V4_UPGRADE` environment variable to true.");
|
||||
return artifactLegacy.create();
|
||||
}
|
||||
else {
|
||||
logger.info("Debug artifacts can be consumed with `actions/download-artifact@v4`.");
|
||||
return new artifact.DefaultArtifactClient();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
||||
|
||||
Reference in New Issue
Block a user