Draft: upload artifacts only in post-init, and combined SARIF artifacts at most once

This commit is contained in:
Angela P Wen
2024-09-05 20:18:29 -07:00
parent 3c37ab48df
commit f249716bf8
30 changed files with 584 additions and 383 deletions
+1 -8
View File
@@ -24,21 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = run;
const core = __importStar(require("@actions/core"));
const actionsUtil = __importStar(require("./actions-util"));
const config_utils_1 = require("./config-utils");
const logging_1 = require("./logging");
async function run(uploadSarifDebugArtifact) {
async function run() {
const logger = (0, logging_1.getActionsLogger)();
const config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error("Config file could not be found at expected location. Did the 'init' action fail to start?");
}
// Upload Actions SARIF artifacts for debugging
if (config?.debugMode) {
core.info("Debug mode is on. Uploading available SARIF files as Actions debugging artifact...");
const outputDir = actionsUtil.getRequiredInput("output");
await uploadSarifDebugArtifact(config, outputDir);
}
}
//# sourceMappingURL=analyze-action-post-helper.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analyze-action-post-helper.js","sourceRoot":"","sources":["../src/analyze-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,kBAuBC;AA7BD,oDAAsC;AAEtC,4DAA8C;AAC9C,iDAAmD;AACnD,uCAA6C;AAEtC,KAAK,UAAU,GAAG,CACvB,wBAGkB;IAElB,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;IAED,+CAA+C;IAC/C,IAAI,MAAM,EAAE,SAAS,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CACP,oFAAoF,CACrF,CAAC;QACF,MAAM,SAAS,GAAG,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,wBAAwB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
{"version":3,"file":"analyze-action-post-helper.js","sourceRoot":"","sources":["../src/analyze-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kBASC;AAbD,4DAA8C;AAC9C,iDAA2C;AAC3C,uCAA6C;AAEtC,KAAK,UAAU,GAAG;IACvB,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAElC,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAS,EAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,MAAM,CAAC,CAAC;IAC5E,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;IACJ,CAAC;AACH,CAAC"}
+44 -71
View File
@@ -1,73 +1,46 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = __importDefault(require("ava"));
const sinon = __importStar(require("sinon"));
const actionsUtil = __importStar(require("./actions-util"));
const analyzeActionPostHelper = __importStar(require("./analyze-action-post-helper"));
const configUtils = __importStar(require("./config-utils"));
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
(0, testing_utils_1.setupTests)(ava_1.default);
(0, ava_1.default)("post: analyze action with debug mode off", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env["RUNNER_TEMP"] = tmpDir;
const gitHubVersion = {
type: util.GitHubVariant.DOTCOM,
};
sinon.stub(configUtils, "getConfig").resolves({
debugMode: false,
gitHubVersion,
languages: [],
packs: [],
});
const uploadSarifSpy = sinon.spy();
await analyzeActionPostHelper.run(uploadSarifSpy);
t.assert(uploadSarifSpy.notCalled);
});
});
(0, ava_1.default)("post: analyze action with debug mode on", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env["RUNNER_TEMP"] = tmpDir;
const gitHubVersion = {
type: util.GitHubVariant.DOTCOM,
};
sinon.stub(configUtils, "getConfig").resolves({
debugMode: true,
gitHubVersion,
languages: [],
packs: [],
});
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
requiredInputStub.withArgs("output").returns("fake-output-dir");
const uploadSarifSpy = sinon.spy();
await analyzeActionPostHelper.run(uploadSarifSpy);
t.assert(uploadSarifSpy.called);
});
});
// import test from "ava";
// import * as sinon from "sinon";
// import * as actionsUtil from "./actions-util";
// import * as analyzeActionPostHelper from "./analyze-action-post-helper";
// import * as configUtils from "./config-utils";
// import { setupTests } from "./testing-utils";
// import * as util from "./util";
// setupTests(test);
// test("post: analyze action with debug mode off", async (t) => {
// return await util.withTmpDir(async (tmpDir) => {
// process.env["RUNNER_TEMP"] = tmpDir;
// const gitHubVersion: util.GitHubVersion = {
// type: util.GitHubVariant.DOTCOM,
// };
// sinon.stub(configUtils, "getConfig").resolves({
// debugMode: false,
// gitHubVersion,
// languages: [],
// packs: [],
// } as unknown as configUtils.Config);
// await analyzeActionPostHelper.run();
// t.assert(uploadSarifSpy.notCalled);
// });
// });
// test("post: analyze action with debug mode on", async (t) => {
// return await util.withTmpDir(async (tmpDir) => {
// // process.env["RUNNER_TEMP"] = tmpDir;
// const gitHubVersion: util.GitHubVersion = {
// type: util.GitHubVariant.DOTCOM,
// };
// sinon.stub(configUtils, "getConfig").resolves({
// debugMode: true,
// gitHubVersion,
// languages: [],
// packs: [],
// } as unknown as configUtils.Config);
// const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
// requiredInputStub.withArgs("output").returns("fake-output-dir");
// const uploadSarifSpy = sinon.spy();
// await analyzeActionPostHelper.run(uploadSarifSpy);
// t.assert(uploadSarifSpy.called);
// });
// });
// TODO: Move these tests!
//# sourceMappingURL=analyze-action-post-helper.test.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analyze-action-post-helper.test.js","sourceRoot":"","sources":["../src/analyze-action-post-helper.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,6CAA+B;AAE/B,4DAA8C;AAC9C,sFAAwE;AACxE,4DAA8C;AAC9C,mDAA6C;AAC7C,6CAA+B;AAE/B,IAAA,0BAAU,EAAC,aAAI,CAAC,CAAC;AAEjB,IAAA,aAAI,EAAC,0CAA0C,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC3D,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;QAEpC,MAAM,aAAa,GAAuB;YACxC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM;SAChC,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC;YAC5C,SAAS,EAAE,KAAK;YACh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AA,0BAA0B;AAC1B,kCAAkC;AAElC,iDAAiD;AACjD,2EAA2E;AAC3E,iDAAiD;AACjD,gDAAgD;AAChD,kCAAkC;AAElC,oBAAoB;AAEpB,kEAAkE;AAClE,qDAAqD;AACrD,2CAA2C;AAE3C,kDAAkD;AAClD,yCAAyC;AACzC,SAAS;AACT,sDAAsD;AACtD,0BAA0B;AAC1B,uBAAuB;AACvB,uBAAuB;AACvB,mBAAmB;AACnB,2CAA2C;AAE3C,2CAA2C;AAE3C,0CAA0C;AAC1C,QAAQ;AACR,MAAM;AAEN,iEAAiE;AACjE,qDAAqD;AACrD,8CAA8C;AAE9C,kDAAkD;AAClD,yCAAyC;AACzC,SAAS;AACT,sDAAsD;AACtD,yBAAyB;AACzB,uBAAuB;AACvB,uBAAuB;AACvB,mBAAmB;AACnB,2CAA2C;AAE3C,6EAA6E;AAC7E,uEAAuE;AAEvE,0CAA0C;AAE1C,yDAAyD;AAEzD,uCAAuC;AACvC,QAAQ;AACR,MAAM;AAEN,0BAA0B"}
+7 -3
View File
@@ -31,14 +31,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const analyzeActionPostHelper = __importStar(require("./analyze-action-post-helper"));
const debugArtifacts = __importStar(require("./debug-artifacts"));
const environment_1 = require("./environment");
const uploadSarifActionPostHelper = __importStar(require("./upload-sarif-action-post-helper"));
const util_1 = require("./util");
async function runWrapper() {
try {
await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact);
// Also run the upload-sarif post action since we're potentially running
await analyzeActionPostHelper.run();
// Also run the upload-sarif post action if we determine that this is a
// first-party analysis run, since we're potentially running
// the same steps in the analyze action.
await uploadSarifActionPostHelper.uploadArtifacts(debugArtifacts.uploadDebugArtifacts);
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] === "true") {
await uploadSarifActionPostHelper.uploadArtifacts(debugArtifacts.uploadDebugArtifacts);
}
}
catch (error) {
core.setFailed(`analyze post-action step failed: ${(0, util_1.wrapError)(error).message}`);
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,sFAAwE;AACxE,kEAAoD;AACpD,+FAAiF;AACjF,iCAAmC;AAEnC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAAM,uBAAuB,CAAC,GAAG,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAC;QAE3E,wEAAwE;QACxE,wCAAwC;QACxC,MAAM,2BAA2B,CAAC,eAAe,CAC/C,cAAc,CAAC,oBAAoB,CACpC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,oCAAoC,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,sFAAwE;AACxE,kEAAoD;AACpD,+CAAuC;AACvC,+FAAiF;AACjF,iCAAmC;AAEnC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAAM,uBAAuB,CAAC,GAAG,EAAE,CAAC;QAEpC,uEAAuE;QACvE,4DAA4D;QAC5D,wCAAwC;QACxC,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,2BAA2B,CAAC,eAAe,CAC/C,cAAc,CAAC,oBAAoB,CACpC,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,oCAAoC,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAC/D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
+1
View File
@@ -163,6 +163,7 @@ async function run() {
}
const apiDetails = (0, api_client_1.getApiDetails)();
const outputDir = actionsUtil.getRequiredInput("output");
core.exportVariable(environment_1.EnvVar.SARIF_RESULTS_OUTPUT_DIR, outputDir);
const threads = util.getThreadsFlag(actionsUtil.getOptionalInput("threads") || process.env["CODEQL_THREADS"], logger);
const repositoryNwo = (0, repository_1.parseRepositoryNwo)(util.getRequiredEnvParam("GITHUB_REPOSITORY"));
const gitHubVersion = await (0, api_client_1.getGitHubVersion)();
File diff suppressed because one or more lines are too long
+135 -55
View File
@@ -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
File diff suppressed because one or more lines are too long
+2
View File
@@ -53,6 +53,8 @@ var EnvVar;
/** Status for the entire job, submitted to the status report in `init-post` */
EnvVar["JOB_STATUS"] = "CODEQL_ACTION_JOB_STATUS";
EnvVar["ODASA_TRACER_CONFIGURATION"] = "ODASA_TRACER_CONFIGURATION";
/** The value of the `output` input for the analyze action. */
EnvVar["SARIF_RESULTS_OUTPUT_DIR"] = "CODEQL_ACTION_SARIF_RESULTS_OUTPUT_DIR";
/**
* What percentage of the total amount of RAM over 8 GB that the Action should reserve for the
* system.
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,MA2FX;AA3FD,WAAY,MAAM;IAChB,2DAA2D;IAC3D,+FAAqF,CAAA;IAErF,6DAA6D;IAC7D,mGAAyF,CAAA;IAEzF;;;OAGG;IACH,4CAAkC,CAAA;IAElC,gEAAgE;IAChE,qEAA2D,CAAA;IAE3D;;;OAGG;IACH,yFAA+E,CAAA;IAE/E;;;OAGG;IACH,yEAA+D,CAAA;IAE/D,gFAAgF;IAChF,6DAAmD,CAAA;IAEnD;;;OAGG;IACH,uEAA6D,CAAA;IAE7D,gEAAgE;IAChE,mEAAyD,CAAA;IAEzD,kFAAkF;IAClF,mFAAyE,CAAA;IAEzE,4CAA4C;IAC5C,4DAAkD,CAAA;IAElD;;;OAGG;I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CAAA;IAEjC;;;;;;OAMG;IACH,4DAAkD,CAAA;IAElD;;;OAGG;IACH,wDAA8C,CAAA;AAChD,CAAC,EA9FW,MAAM,sBAAN,MAAM,QA8FjB"}
+10 -3
View File
@@ -106,7 +106,13 @@ async function tryUploadSarifIfRunFailed(config, repositoryNwo, features, logger
};
}
}
async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, printDebugLogs, config, repositoryNwo, features, logger) {
async function run(
// uploadDatabaseBundleDebugArtifact: (
// config: Config,
// logger: Logger,
// ) => Promise<void>,
// uploadLogsDebugArtifact: (config: Config) => Promise<void>,
uploadAllAvailableDebugArtifacts, printDebugLogs, config, repositoryNwo, features, logger) {
const uploadFailedSarifResult = await tryUploadSarifIfRunFailed(config, repositoryNwo, features, logger);
if (uploadFailedSarifResult.upload_failed_run_skipped_because) {
logger.debug("Won't upload a failed SARIF file for this CodeQL code scanning run because: " +
@@ -132,8 +138,9 @@ async function run(uploadDatabaseBundleDebugArtifact, uploadLogsDebugArtifact, p
// Upload appropriate Actions artifacts for debugging
if (config.debugMode) {
logger.info("Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...");
await uploadDatabaseBundleDebugArtifact(config, logger);
await uploadLogsDebugArtifact(config);
// await uploadDatabaseBundleDebugArtifact(config, logger);
// await uploadLogsDebugArtifact(config);
await uploadAllAvailableDebugArtifacts(config, logger);
await printDebugLogs(config);
}
if (actionsUtil.isSelfHostedRunner()) {
File diff suppressed because one or more lines are too long
+20 -10
View File
@@ -53,12 +53,17 @@ const workflow = __importStar(require("./workflow"));
languages: [],
packs: [],
});
const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
// const uploadDatabaseBundleSpy = sinon.spy();
// const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();
await initActionPostHelper.run(uploadDatabaseBundleSpy, uploadLogsSpy, printDebugLogsSpy, (0, testing_utils_1.createTestConfig)({ debugMode: false }), (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
t.assert(uploadDatabaseBundleSpy.notCalled);
t.assert(uploadLogsSpy.notCalled);
await initActionPostHelper.run(
// uploadDatabaseBundleSpy,
// uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy, printDebugLogsSpy, (0, testing_utils_1.createTestConfig)({ debugMode: false }), (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
// t.assert(uploadDatabaseBundleSpy.notCalled);
// t.assert(uploadLogsSpy.notCalled);
t.assert(uploadAllAvailableDebugArtifactsSpy.notCalled);
t.assert(printDebugLogsSpy.notCalled);
});
});
@@ -66,12 +71,17 @@ const workflow = __importStar(require("./workflow"));
return await util.withTmpDir(async (tmpDir) => {
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
process.env["RUNNER_TEMP"] = tmpDir;
const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
// const uploadDatabaseBundleSpy = sinon.spy();
// const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();
await initActionPostHelper.run(uploadDatabaseBundleSpy, uploadLogsSpy, printDebugLogsSpy, (0, testing_utils_1.createTestConfig)({ debugMode: true }), (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
t.assert(uploadDatabaseBundleSpy.called);
t.assert(uploadLogsSpy.called);
await initActionPostHelper.run(
// uploadDatabaseBundleSpy,
// uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy, printDebugLogsSpy, (0, testing_utils_1.createTestConfig)({ debugMode: true }), (0, repository_1.parseRepositoryNwo)("github/codeql-action"), (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
// t.assert(uploadDatabaseBundleSpy.called);
// t.assert(uploadLogsSpy.called);
t.assert(uploadAllAvailableDebugArtifactsSpy.called);
t.assert(printDebugLogsSpy.called);
});
});
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -54,7 +54,10 @@ async function runWrapper() {
logger.warning("Debugging artifacts are unavailable since the 'init' Action failed before it could produce any.");
return;
}
uploadFailedSarifResult = await initActionPostHelper.run(debugArtifacts.uploadDatabaseBundleDebugArtifact, debugArtifacts.uploadLogsDebugArtifact, actions_util_1.printDebugLogs, config, repositoryNwo, features, logger);
uploadFailedSarifResult = await initActionPostHelper.run(
// debugArtifacts.uploadDatabaseBundleDebugArtifact,
// debugArtifacts.uploadLogsDebugArtifact,
debugArtifacts.uploadAllAvailableDebugArtifacts, actions_util_1.printDebugLogs, config, repositoryNwo, features, logger);
}
catch (unwrappedError) {
const error = (0, util_1.wrapError)(unwrappedError);
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"init-action-post.js","sourceRoot":"","sources":["../src/init-action-post.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AAEtC,iDAAuE;AACvE,6CAAgD;AAChD,iDAAmD;AACnD,kEAAoD;AACpD,mDAA2C;AAC3C,gFAAkE;AAClE,uCAA6C;AAC7C,6CAAkD;AAClD,mDAOyB;AACzB,iCAKgB;AAOhB,KAAK,UAAU,UAAU;IACvB,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,IAAI,MAA0B,CAAC;IAC/B,IAAI,uBAES,CAAC;IACd,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,IAAA,6BAAgB,GAAE,CAAC;QAC/C,IAAA,gCAAyB,EAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAEjD,MAAM,aAAa,GAAG,IAAA,+BAAkB,EACtC,IAAA,0BAAmB,EAAC,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SAAS,EAAE,CAAC;QACnC,MAAM,YAAY,GAAyB;YACzC,GAAG,gBAAgB;YACnB,GAAG,uBAAuB;YAC1B,UAAU,EAAE,oBAAoB,CAAC,iBAAiB,EAAE;SACrD,CAAC;QACF,MAAM,IAAA,gCAAgB,EAAC,YAAY,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
+41 -20
View File
@@ -24,33 +24,54 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadArtifacts = uploadArtifacts;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const core = __importStar(require("@actions/core"));
const actionsUtil = __importStar(require("./actions-util"));
const configUtils = __importStar(require("./config-utils"));
const debug_artifacts_1 = require("./debug-artifacts");
const environment_1 = require("./environment");
async function uploadArtifacts(uploadDebugArtifacts) {
const tempDir = actionsUtil.getTemporaryDirectory();
// Upload Actions SARIF artifacts for debugging when environment variable is set
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
core.info("Uploading available combined SARIF files as Actions debugging artifact...");
// Upload debug artifacts here only if this is third-party analysis.
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
const tempDir = actionsUtil.getTemporaryDirectory();
const baseTempDir = path.resolve(tempDir, "combined-sarif");
const toUpload = [];
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) {
toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
}
}
}
const config = await configUtils.getConfig(actionsUtil.getTemporaryDirectory(), core);
if (toUpload.length > 0) {
await uploadDebugArtifacts(toUpload, baseTempDir, "upload-debug-artifacts", config?.gitHubVersion.type);
const combinedSarifDebugArtifacts = (0, debug_artifacts_1.getCombinedSarifDebugArtifacts)(baseTempDir);
if (combinedSarifDebugArtifacts.length > 0) {
const config = await configUtils.getConfig(tempDir, core);
await uploadDebugArtifacts(combinedSarifDebugArtifacts, baseTempDir, "upload-debug-artifacts", config?.gitHubVersion.type);
}
}
// const tempDir = actionsUtil.getTemporaryDirectory();
// // Upload Actions SARIF artifacts for debugging when environment variable is set
// if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
// core.info(
// "Uploading available combined SARIF files as Actions debugging artifact...",
// );
// const baseTempDir = path.resolve(tempDir, "combined-sarif");
// const toUpload: string[] = [];
// 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) {
// toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
// }
// }
// }
// const config = await configUtils.getConfig(
// actionsUtil.getTemporaryDirectory(),
// core,
// );
// if (toUpload.length > 0) {
// await uploadDebugArtifacts(
// toUpload,
// baseTempDir,
// "upload-debug-artifacts",
// config?.gitHubVersion.type,
// );
// }
// }
}
//# sourceMappingURL=upload-sarif-action-post-helper.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"upload-sarif-action-post-helper.js","sourceRoot":"","sources":["../src/upload-sarif-action-post-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AASA,0CAgDC;AAzDD,uCAAyB;AACzB,2CAA6B;AAE7B,oDAAsC;AAEtC,4DAA8C;AAC9C,4DAA8C;AAGvC,KAAK,UAAU,eAAe,CACnC,oBAKkB;IAElB,MAAM,OAAO,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;IAEpD,gFAAgF;IAChF,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,KAAK,MAAM,EAAE,CAAC;QACjE,IAAI,CAAC,IAAI,CACP,2EAA2E,CAC5E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K,UAAU,eAAe,CACnC,oBAKkB;IAElB,oEAAoE;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;QACvD,MAAM,OAAO,GAAG,WAAW,CAAC,qBAAqB,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAE5D,MAAM,2BAA2B,GAC/B,IAAA,gDAA8B,EAAC,WAAW,CAAC,CAAC;QAC9C,IAAI,2BAA2B,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1D,MAAM,oBAAoB,CACxB,2BAA2B,EAC3B,WAAW,EACX,wBAAwB,EACxB,MAAM,EAAE,aAAa,CAAC,IAAI,CAC3B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,uDAAuD;IAEvD,mFAAmF;IACnF,sEAAsE;IACtE,eAAe;IACf,mFAAmF;IACnF,OAAO;IAEP,iEAAiE;IAEjE,mCAAmC;IAEnC,sCAAsC;IACtC,sDAAsD;IAEtD,4CAA4C;IAC5C,8BAA8B;IAC9B,6DAA6D;IAC7D,gDAAgD;IAEhD,8CAA8C;IAC9C,0EAA0E;IAC1E,UAAU;IACV,QAAQ;IACR,MAAM;IAEN,gDAAgD;IAChD,2CAA2C;IAC3C,YAAY;IACZ,OAAO;IAEP,+BAA+B;IAC/B,kCAAkC;IAClC,kBAAkB;IAClB,qBAAqB;IACrB,kCAAkC;IAClC,oCAAoC;IACpC,SAAS;IACT,MAAM;IACN,IAAI;AACN,CAAC"}
+44 -44
View File
@@ -1,57 +1,57 @@
import test from "ava";
import * as sinon from "sinon";
// import test from "ava";
// import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import * as analyzeActionPostHelper from "./analyze-action-post-helper";
import * as configUtils from "./config-utils";
import { setupTests } from "./testing-utils";
import * as util from "./util";
// import * as actionsUtil from "./actions-util";
// import * as analyzeActionPostHelper from "./analyze-action-post-helper";
// import * as configUtils from "./config-utils";
// import { setupTests } from "./testing-utils";
// import * as util from "./util";
setupTests(test);
// setupTests(test);
test("post: analyze action with debug mode off", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env["RUNNER_TEMP"] = tmpDir;
// test("post: analyze action with debug mode off", async (t) => {
// return await util.withTmpDir(async (tmpDir) => {
// process.env["RUNNER_TEMP"] = tmpDir;
const gitHubVersion: util.GitHubVersion = {
type: util.GitHubVariant.DOTCOM,
};
sinon.stub(configUtils, "getConfig").resolves({
debugMode: false,
gitHubVersion,
languages: [],
packs: [],
} as unknown as configUtils.Config);
// const gitHubVersion: util.GitHubVersion = {
// type: util.GitHubVariant.DOTCOM,
// };
// sinon.stub(configUtils, "getConfig").resolves({
// debugMode: false,
// gitHubVersion,
// languages: [],
// packs: [],
// } as unknown as configUtils.Config);
const uploadSarifSpy = sinon.spy();
// await analyzeActionPostHelper.run();
await analyzeActionPostHelper.run(uploadSarifSpy);
// t.assert(uploadSarifSpy.notCalled);
// });
// });
t.assert(uploadSarifSpy.notCalled);
});
});
// test("post: analyze action with debug mode on", async (t) => {
// return await util.withTmpDir(async (tmpDir) => {
// // process.env["RUNNER_TEMP"] = tmpDir;
test("post: analyze action with debug mode on", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env["RUNNER_TEMP"] = tmpDir;
// const gitHubVersion: util.GitHubVersion = {
// type: util.GitHubVariant.DOTCOM,
// };
// sinon.stub(configUtils, "getConfig").resolves({
// debugMode: true,
// gitHubVersion,
// languages: [],
// packs: [],
// } as unknown as configUtils.Config);
const gitHubVersion: util.GitHubVersion = {
type: util.GitHubVariant.DOTCOM,
};
sinon.stub(configUtils, "getConfig").resolves({
debugMode: true,
gitHubVersion,
languages: [],
packs: [],
} as unknown as configUtils.Config);
// const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
// requiredInputStub.withArgs("output").returns("fake-output-dir");
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
requiredInputStub.withArgs("output").returns("fake-output-dir");
// const uploadSarifSpy = sinon.spy();
const uploadSarifSpy = sinon.spy();
// await analyzeActionPostHelper.run(uploadSarifSpy);
await analyzeActionPostHelper.run(uploadSarifSpy);
// t.assert(uploadSarifSpy.called);
// });
// });
t.assert(uploadSarifSpy.called);
});
});
// TODO: Move these tests!
+2 -18
View File
@@ -1,15 +1,8 @@
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import { Config, getConfig } from "./config-utils";
import { getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";
export async function run(
uploadSarifDebugArtifact: (
config: Config,
outputDir: string,
) => Promise<void>,
) {
export async function run() {
const logger = getActionsLogger();
const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
@@ -18,13 +11,4 @@ export async function run(
"Config file could not be found at expected location. Did the 'init' action fail to start?",
);
}
// Upload Actions SARIF artifacts for debugging
if (config?.debugMode) {
core.info(
"Debug mode is on. Uploading available SARIF files as Actions debugging artifact...",
);
const outputDir = actionsUtil.getRequiredInput("output");
await uploadSarifDebugArtifact(config, outputDir);
}
}
+9 -5
View File
@@ -7,18 +7,22 @@ import * as core from "@actions/core";
import * as analyzeActionPostHelper from "./analyze-action-post-helper";
import * as debugArtifacts from "./debug-artifacts";
import { EnvVar } from "./environment";
import * as uploadSarifActionPostHelper from "./upload-sarif-action-post-helper";
import { wrapError } from "./util";
async function runWrapper() {
try {
await analyzeActionPostHelper.run(debugArtifacts.uploadSarifDebugArtifact);
await analyzeActionPostHelper.run();
// Also run the upload-sarif post action since we're potentially running
// Also run the upload-sarif post action if we determine that this is a
// first-party analysis run, since we're potentially running
// the same steps in the analyze action.
await uploadSarifActionPostHelper.uploadArtifacts(
debugArtifacts.uploadDebugArtifacts,
);
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] === "true") {
await uploadSarifActionPostHelper.uploadArtifacts(
debugArtifacts.uploadDebugArtifacts,
);
}
} catch (error) {
core.setFailed(
`analyze post-action step failed: ${wrapError(error).message}`,
+1
View File
@@ -230,6 +230,7 @@ async function run() {
const apiDetails = getApiDetails();
const outputDir = actionsUtil.getRequiredInput("output");
core.exportVariable(EnvVar.SARIF_RESULTS_OUTPUT_DIR, outputDir);
const threads = util.getThreadsFlag(
actionsUtil.getOptionalInput("threads") || process.env["CODEQL_THREADS"],
logger,
+169 -85
View File
@@ -7,10 +7,11 @@ import * as core from "@actions/core";
import AdmZip from "adm-zip";
import del from "del";
import { getRequiredInput } from "./actions-util";
import { getRequiredInput, getTemporaryDirectory } from "./actions-util";
import { dbIsFinalized } from "./analyze";
import { getCodeQL } from "./codeql";
import { Config } from "./config-utils";
import { EnvVar } from "./environment";
import { Language } from "./languages";
import { Logger } from "./logging";
import {
@@ -25,6 +26,91 @@ export function sanitizeArifactName(name: string): string {
return name.replace(/[^a-zA-Z0-9_\\-]+/g, "");
}
export function getCombinedSarifDebugArtifacts(baseTempDir: string): string[] {
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] !== "true") {
return [];
}
core.info(
"Uploading available combined SARIF files as Actions debugging artifact...",
);
const combinedSarifFiles: string[] = [];
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;
}
export async function uploadAllAvailableDebugArtifacts(
config: Config,
logger: Logger,
) {
let filesToUpload: string[] = [];
const analyzeActionOutputDir = process.env[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 = getCodeQLDatabasePath(config, lang);
const logsDirectory = path.resolve(databaseDirectory, "log");
if (doesDirectoryExist(logsDirectory)) {
filesToUpload = filesToUpload.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)) {
filesToUpload = filesToUpload.concat(
listFolder(multiLanguageTracingLogsDirectory),
);
}
// DB Bundle
let databaseBundlePath: string;
if (!dbIsFinalized(config, lang, logger)) {
databaseBundlePath = await createPartialDatabaseBundle(config, lang);
} else {
databaseBundlePath = await createDatabaseBundleCli(config, lang);
}
filesToUpload = filesToUpload.concat(databaseBundlePath);
}
await uploadDebugArtifacts(
filesToUpload,
getTemporaryDirectory(),
config.debugArtifactName,
config.gitHubVersion.type,
);
}
export async function uploadDebugArtifacts(
toUpload: string[],
rootDir: string,
@@ -72,17 +158,15 @@ export async function uploadDebugArtifacts(
} 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) {
// A failure to upload debug artifacts should not fail the entire action.
@@ -90,55 +174,55 @@ export async function uploadDebugArtifacts(
}
}
export async function uploadSarifDebugArtifact(
config: Config,
outputDir: string,
) {
if (!doesDirectoryExist(outputDir)) {
return;
}
// 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,
);
}
// 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));
}
}
// 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));
}
// // 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,
);
}
// await uploadDebugArtifacts(
// toUpload,
// config.dbLocation,
// config.debugArtifactName,
// config.gitHubVersion.type,
// );
// }
/**
* If a database has not been finalized, we cannot run the `codeql database bundle`
@@ -184,31 +268,31 @@ async function createDatabaseBundleCli(
return databaseBundlePath;
}
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}`,
);
}
}
}
// 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}`,
// );
// }
// }
// }
+3
View File
@@ -64,6 +64,9 @@ export enum EnvVar {
ODASA_TRACER_CONFIGURATION = "ODASA_TRACER_CONFIGURATION",
/** The value of the `output` input for the analyze action. */
SARIF_RESULTS_OUTPUT_DIR = "CODEQL_ACTION_SARIF_RESULTS_OUTPUT_DIR",
/**
* What percentage of the total amount of RAM over 8 GB that the Action should reserve for the
* system.
+18 -12
View File
@@ -35,13 +35,15 @@ test("post: init action with debug mode off", async (t) => {
packs: [],
} as unknown as configUtils.Config);
const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
// const uploadDatabaseBundleSpy = sinon.spy();
// const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();
await initActionPostHelper.run(
uploadDatabaseBundleSpy,
uploadLogsSpy,
// uploadDatabaseBundleSpy,
// uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: false }),
parseRepositoryNwo("github/codeql-action"),
@@ -49,8 +51,9 @@ test("post: init action with debug mode off", async (t) => {
getRunnerLogger(true),
);
t.assert(uploadDatabaseBundleSpy.notCalled);
t.assert(uploadLogsSpy.notCalled);
// t.assert(uploadDatabaseBundleSpy.notCalled);
// t.assert(uploadLogsSpy.notCalled);
t.assert(uploadAllAvailableDebugArtifactsSpy.notCalled);
t.assert(printDebugLogsSpy.notCalled);
});
});
@@ -60,13 +63,15 @@ test("post: init action with debug mode on", async (t) => {
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
process.env["RUNNER_TEMP"] = tmpDir;
const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
// const uploadDatabaseBundleSpy = sinon.spy();
// const uploadLogsSpy = sinon.spy();
const uploadAllAvailableDebugArtifactsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();
await initActionPostHelper.run(
uploadDatabaseBundleSpy,
uploadLogsSpy,
// uploadDatabaseBundleSpy,
// uploadLogsSpy,
uploadAllAvailableDebugArtifactsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: true }),
parseRepositoryNwo("github/codeql-action"),
@@ -74,8 +79,9 @@ test("post: init action with debug mode on", async (t) => {
getRunnerLogger(true),
);
t.assert(uploadDatabaseBundleSpy.called);
t.assert(uploadLogsSpy.called);
// t.assert(uploadDatabaseBundleSpy.called);
// t.assert(uploadLogsSpy.called);
t.assert(uploadAllAvailableDebugArtifactsSpy.called);
t.assert(printDebugLogsSpy.called);
});
});
+9 -4
View File
@@ -158,11 +158,15 @@ export async function tryUploadSarifIfRunFailed(
}
export async function run(
uploadDatabaseBundleDebugArtifact: (
// uploadDatabaseBundleDebugArtifact: (
// config: Config,
// logger: Logger,
// ) => Promise<void>,
// uploadLogsDebugArtifact: (config: Config) => Promise<void>,
uploadAllAvailableDebugArtifacts: (
config: Config,
logger: Logger,
) => Promise<void>,
uploadLogsDebugArtifact: (config: Config) => Promise<void>,
printDebugLogs: (config: Config) => Promise<void>,
config: Config,
repositoryNwo: RepositoryNwo,
@@ -211,8 +215,9 @@ export async function run(
logger.info(
"Debug mode is on. Uploading available database bundles and logs as Actions debugging artifacts...",
);
await uploadDatabaseBundleDebugArtifact(config, logger);
await uploadLogsDebugArtifact(config);
// await uploadDatabaseBundleDebugArtifact(config, logger);
// await uploadLogsDebugArtifact(config);
await uploadAllAvailableDebugArtifacts(config, logger);
await printDebugLogs(config);
}
+3 -2
View File
@@ -64,8 +64,9 @@ async function runWrapper() {
}
uploadFailedSarifResult = await initActionPostHelper.run(
debugArtifacts.uploadDatabaseBundleDebugArtifact,
debugArtifacts.uploadLogsDebugArtifact,
// debugArtifacts.uploadDatabaseBundleDebugArtifact,
// debugArtifacts.uploadLogsDebugArtifact,
debugArtifacts.uploadAllAvailableDebugArtifacts,
printDebugLogs,
config,
repositoryNwo,
+51 -32
View File
@@ -1,10 +1,11 @@
import * as fs from "fs";
import * as path from "path";
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import * as configUtils from "./config-utils";
import { getCombinedSarifDebugArtifacts } from "./debug-artifacts";
import { EnvVar } from "./environment";
import { GitHubVariant } from "./util";
export async function uploadArtifacts(
@@ -15,44 +16,62 @@ export async function uploadArtifacts(
ghVariant: GitHubVariant | undefined,
) => Promise<void>,
) {
const tempDir = actionsUtil.getTemporaryDirectory();
// Upload Actions SARIF artifacts for debugging when environment variable is set
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
core.info(
"Uploading available combined SARIF files as Actions debugging artifact...",
);
// Upload debug artifacts here only if this is third-party analysis.
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
const tempDir = actionsUtil.getTemporaryDirectory();
const baseTempDir = path.resolve(tempDir, "combined-sarif");
const toUpload: string[] = [];
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) {
toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
}
}
}
const config = await configUtils.getConfig(
actionsUtil.getTemporaryDirectory(),
core,
);
if (toUpload.length > 0) {
const combinedSarifDebugArtifacts =
getCombinedSarifDebugArtifacts(baseTempDir);
if (combinedSarifDebugArtifacts.length > 0) {
const config = await configUtils.getConfig(tempDir, core);
await uploadDebugArtifacts(
toUpload,
combinedSarifDebugArtifacts,
baseTempDir,
"upload-debug-artifacts",
config?.gitHubVersion.type,
);
}
}
// const tempDir = actionsUtil.getTemporaryDirectory();
// // Upload Actions SARIF artifacts for debugging when environment variable is set
// if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
// core.info(
// "Uploading available combined SARIF files as Actions debugging artifact...",
// );
// const baseTempDir = path.resolve(tempDir, "combined-sarif");
// const toUpload: string[] = [];
// 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) {
// toUpload.push(path.resolve(baseTempDir, outputDir, sarifFile));
// }
// }
// }
// const config = await configUtils.getConfig(
// actionsUtil.getTemporaryDirectory(),
// core,
// );
// if (toUpload.length > 0) {
// await uploadDebugArtifacts(
// toUpload,
// baseTempDir,
// "upload-debug-artifacts",
// config?.gitHubVersion.type,
// );
// }
// }
}