mirror of
https://github.com/github/codeql-action.git
synced 2026-05-12 17:00:15 +00:00
Upload with artifacts-legacy when running GHES, else with artifacts
`@actions/artifacts@v1` is still not yet supported on GHES and we need to maintain backwards compatibility here. If we detect that a user is running on GHES, we fall back on the original `v1` import.
This commit is contained in:
Generated
+23
-9
@@ -34,6 +34,7 @@ exports.uploadDatabaseBundleDebugArtifact = uploadDatabaseBundleDebugArtifact;
|
||||
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"));
|
||||
@@ -44,10 +45,14 @@ const util_1 = require("./util");
|
||||
function sanitizeArifactName(name) {
|
||||
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
|
||||
}
|
||||
async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
|
||||
async function uploadDebugArtifacts(toUpload, rootDir, artifactName, ghVariant) {
|
||||
if (toUpload.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (ghVariant === undefined) {
|
||||
core.warning(`Did not upload debug artifacts because cannot determine the GitHub variant running.`);
|
||||
return;
|
||||
}
|
||||
let suffix = "";
|
||||
const matrix = (0, actions_util_1.getRequiredInput)("matrix");
|
||||
if (matrix) {
|
||||
@@ -60,11 +65,20 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
await artifact.create().uploadArtifact(sanitizeArifactName(`${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,
|
||||
});
|
||||
if (ghVariant === util_1.GitHubVariant.GHES) {
|
||||
await artifactLegacy.create().uploadArtifact(sanitizeArifactName(`${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,
|
||||
});
|
||||
}
|
||||
else {
|
||||
const artifactClient = new artifact.DefaultArtifactClient();
|
||||
await artifactClient.uploadArtifact(sanitizeArifactName(`${artifactName}${suffix}`), toUpload, 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.
|
||||
@@ -82,7 +96,7 @@ async function uploadSarifDebugArtifact(config, outputDir) {
|
||||
toUpload = toUpload.concat(sarifFile);
|
||||
}
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, outputDir, config.debugArtifactName);
|
||||
await uploadDebugArtifacts(toUpload, outputDir, config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
async function uploadLogsDebugArtifact(config) {
|
||||
let toUpload = [];
|
||||
@@ -98,7 +112,7 @@ async function uploadLogsDebugArtifact(config) {
|
||||
if ((0, util_1.doesDirectoryExist)(multiLanguageTracingLogsDirectory)) {
|
||||
toUpload = toUpload.concat((0, util_1.listFolder)(multiLanguageTracingLogsDirectory));
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName);
|
||||
await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
/**
|
||||
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
||||
@@ -136,7 +150,7 @@ async function uploadDatabaseBundleDebugArtifact(config, logger) {
|
||||
else {
|
||||
databaseBundlePath = await createDatabaseBundleCli(config, language);
|
||||
}
|
||||
await uploadDebugArtifacts([databaseBundlePath], config.dbLocation, config.debugArtifactName);
|
||||
await uploadDebugArtifacts([databaseBundlePath], config.dbLocation, config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
catch (error) {
|
||||
core.info(`Failed to upload database debug bundle for ${config.debugDatabaseName}-${language}: ${error}`);
|
||||
|
||||
Reference in New Issue
Block a user