mirror of
https://github.com/github/codeql-action.git
synced 2026-05-12 08:40:13 +00:00
Draft: upload artifacts only in post-init, and combined SARIF artifacts at most once
This commit is contained in:
Generated
+135
-55
@@ -27,10 +27,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sanitizeArifactName = sanitizeArifactName;
|
||||
exports.getCombinedSarifDebugArtifacts = getCombinedSarifDebugArtifacts;
|
||||
exports.uploadAllAvailableDebugArtifacts = uploadAllAvailableDebugArtifacts;
|
||||
exports.uploadDebugArtifacts = uploadDebugArtifacts;
|
||||
exports.uploadSarifDebugArtifact = uploadSarifDebugArtifact;
|
||||
exports.uploadLogsDebugArtifact = uploadLogsDebugArtifact;
|
||||
exports.uploadDatabaseBundleDebugArtifact = uploadDatabaseBundleDebugArtifact;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const artifact = __importStar(require("@actions/artifact"));
|
||||
@@ -41,10 +40,66 @@ const del_1 = __importDefault(require("del"));
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const analyze_1 = require("./analyze");
|
||||
const codeql_1 = require("./codeql");
|
||||
const environment_1 = require("./environment");
|
||||
const util_1 = require("./util");
|
||||
function sanitizeArifactName(name) {
|
||||
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
|
||||
}
|
||||
function getCombinedSarifDebugArtifacts(baseTempDir) {
|
||||
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] !== "true") {
|
||||
return [];
|
||||
}
|
||||
core.info("Uploading available combined SARIF files as Actions debugging artifact...");
|
||||
const combinedSarifFiles = [];
|
||||
if (fs.existsSync(baseTempDir)) {
|
||||
const outputDirs = fs.readdirSync(baseTempDir);
|
||||
for (const outputDir of outputDirs) {
|
||||
const sarifFiles = fs
|
||||
.readdirSync(path.resolve(baseTempDir, outputDir))
|
||||
.filter((f) => f.endsWith(".sarif"));
|
||||
for (const sarifFile of sarifFiles) {
|
||||
combinedSarifFiles.push(path.resolve(baseTempDir, outputDir, sarifFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
return combinedSarifFiles;
|
||||
}
|
||||
async function uploadAllAvailableDebugArtifacts(config, logger) {
|
||||
let filesToUpload = [];
|
||||
const analyzeActionOutputDir = process.env[environment_1.EnvVar.SARIF_RESULTS_OUTPUT_DIR];
|
||||
for (const lang of config.languages) {
|
||||
// SARIF
|
||||
if (analyzeActionOutputDir !== undefined &&
|
||||
fs.existsSync(analyzeActionOutputDir) &&
|
||||
fs.lstatSync(analyzeActionOutputDir).isDirectory()) {
|
||||
const sarifFile = path.resolve(analyzeActionOutputDir, `${lang}.sarif`);
|
||||
if (fs.existsSync(sarifFile)) {
|
||||
filesToUpload = filesToUpload.concat(sarifFile);
|
||||
}
|
||||
}
|
||||
// Logs
|
||||
const databaseDirectory = (0, util_1.getCodeQLDatabasePath)(config, lang);
|
||||
const logsDirectory = path.resolve(databaseDirectory, "log");
|
||||
if ((0, util_1.doesDirectoryExist)(logsDirectory)) {
|
||||
filesToUpload = filesToUpload.concat((0, util_1.listFolder)(logsDirectory));
|
||||
}
|
||||
// Multilanguage tracing: there are additional logs in the root of the cluster
|
||||
const multiLanguageTracingLogsDirectory = path.resolve(config.dbLocation, "log");
|
||||
if ((0, util_1.doesDirectoryExist)(multiLanguageTracingLogsDirectory)) {
|
||||
filesToUpload = filesToUpload.concat((0, util_1.listFolder)(multiLanguageTracingLogsDirectory));
|
||||
}
|
||||
// DB Bundle
|
||||
let databaseBundlePath;
|
||||
if (!(0, analyze_1.dbIsFinalized)(config, lang, logger)) {
|
||||
databaseBundlePath = await createPartialDatabaseBundle(config, lang);
|
||||
}
|
||||
else {
|
||||
databaseBundlePath = await createDatabaseBundleCli(config, lang);
|
||||
}
|
||||
filesToUpload = filesToUpload.concat(databaseBundlePath);
|
||||
}
|
||||
await uploadDebugArtifacts(filesToUpload, (0, actions_util_1.getTemporaryDirectory)(), config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
async function uploadDebugArtifacts(toUpload, rootDir, artifactName, ghVariant) {
|
||||
if (toUpload.length === 0) {
|
||||
return;
|
||||
@@ -74,12 +129,10 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName, ghVariant)
|
||||
}
|
||||
else {
|
||||
const artifactClient = new artifact.DefaultArtifactClient();
|
||||
for (const file of toUpload) {
|
||||
await artifactClient.uploadArtifact(sanitizeArifactName(`${artifactName}${suffix}-${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,
|
||||
});
|
||||
}
|
||||
await artifactClient.uploadArtifact(sanitizeArifactName(`${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) {
|
||||
@@ -87,35 +140,51 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName, ghVariant)
|
||||
core.warning(`Failed to upload debug artifacts: ${e}`);
|
||||
}
|
||||
}
|
||||
async function uploadSarifDebugArtifact(config, outputDir) {
|
||||
if (!(0, util_1.doesDirectoryExist)(outputDir)) {
|
||||
return;
|
||||
}
|
||||
let toUpload = [];
|
||||
for (const lang of config.languages) {
|
||||
const sarifFile = path.resolve(outputDir, `${lang}.sarif`);
|
||||
if (fs.existsSync(sarifFile)) {
|
||||
toUpload = toUpload.concat(sarifFile);
|
||||
}
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, outputDir, config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
async function uploadLogsDebugArtifact(config) {
|
||||
let toUpload = [];
|
||||
for (const language of config.languages) {
|
||||
const databaseDirectory = (0, util_1.getCodeQLDatabasePath)(config, language);
|
||||
const logsDirectory = path.resolve(databaseDirectory, "log");
|
||||
if ((0, util_1.doesDirectoryExist)(logsDirectory)) {
|
||||
toUpload = toUpload.concat((0, util_1.listFolder)(logsDirectory));
|
||||
}
|
||||
}
|
||||
// Multilanguage tracing: there are additional logs in the root of the cluster
|
||||
const multiLanguageTracingLogsDirectory = path.resolve(config.dbLocation, "log");
|
||||
if ((0, util_1.doesDirectoryExist)(multiLanguageTracingLogsDirectory)) {
|
||||
toUpload = toUpload.concat((0, util_1.listFolder)(multiLanguageTracingLogsDirectory));
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, config.dbLocation, config.debugArtifactName, config.gitHubVersion.type);
|
||||
}
|
||||
// export async function uploadSarifDebugArtifact(
|
||||
// config: Config,
|
||||
// outputDir: string,
|
||||
// ) {
|
||||
// if (!doesDirectoryExist(outputDir)) {
|
||||
// return;
|
||||
// }
|
||||
// let toUpload: string[] = [];
|
||||
// for (const lang of config.languages) {
|
||||
// const sarifFile = path.resolve(outputDir, `${lang}.sarif`);
|
||||
// if (fs.existsSync(sarifFile)) {
|
||||
// toUpload = toUpload.concat(sarifFile);
|
||||
// }
|
||||
// }
|
||||
// await uploadDebugArtifacts(
|
||||
// toUpload,
|
||||
// outputDir,
|
||||
// `${config.debugArtifactName}`,
|
||||
// config.gitHubVersion.type,
|
||||
// );
|
||||
// }
|
||||
// export async function uploadLogsDebugArtifact(config: Config) {
|
||||
// let toUpload: string[] = [];
|
||||
// for (const language of config.languages) {
|
||||
// const databaseDirectory = getCodeQLDatabasePath(config, language);
|
||||
// const logsDirectory = path.resolve(databaseDirectory, "log");
|
||||
// if (doesDirectoryExist(logsDirectory)) {
|
||||
// toUpload = toUpload.concat(listFolder(logsDirectory));
|
||||
// }
|
||||
// }
|
||||
// // Multilanguage tracing: there are additional logs in the root of the cluster
|
||||
// const multiLanguageTracingLogsDirectory = path.resolve(
|
||||
// config.dbLocation,
|
||||
// "log",
|
||||
// );
|
||||
// if (doesDirectoryExist(multiLanguageTracingLogsDirectory)) {
|
||||
// toUpload = toUpload.concat(listFolder(multiLanguageTracingLogsDirectory));
|
||||
// }
|
||||
// await uploadDebugArtifacts(
|
||||
// toUpload,
|
||||
// config.dbLocation,
|
||||
// config.debugArtifactName,
|
||||
// config.gitHubVersion.type,
|
||||
// );
|
||||
// }
|
||||
/**
|
||||
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
||||
* command in the CLI because it will return an error. Instead we directly zip
|
||||
@@ -142,21 +211,32 @@ async function createDatabaseBundleCli(config, language) {
|
||||
const databaseBundlePath = await (0, util_1.bundleDb)(config, language, await (0, codeql_1.getCodeQL)(config.codeQLCmd), `${config.debugDatabaseName}-${language}`);
|
||||
return databaseBundlePath;
|
||||
}
|
||||
async function uploadDatabaseBundleDebugArtifact(config, logger) {
|
||||
for (const language of config.languages) {
|
||||
try {
|
||||
let databaseBundlePath;
|
||||
if (!(0, analyze_1.dbIsFinalized)(config, language, logger)) {
|
||||
databaseBundlePath = await createPartialDatabaseBundle(config, language);
|
||||
}
|
||||
else {
|
||||
databaseBundlePath = await createDatabaseBundleCli(config, language);
|
||||
}
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// export async function uploadDatabaseBundleDebugArtifact(
|
||||
// config: Config,
|
||||
// logger: Logger,
|
||||
// ) {
|
||||
// for (const language of config.languages) {
|
||||
// try {
|
||||
// let databaseBundlePath: string;
|
||||
// if (!dbIsFinalized(config, language, logger)) {
|
||||
// databaseBundlePath = await createPartialDatabaseBundle(
|
||||
// config,
|
||||
// language,
|
||||
// );
|
||||
// } else {
|
||||
// databaseBundlePath = await createDatabaseBundleCli(config, language);
|
||||
// }
|
||||
// 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}`,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//# sourceMappingURL=debug-artifacts.js.map
|
||||
Reference in New Issue
Block a user