Improve logging for combined SARIF debug artifact
This commit is contained in:
parent
d0a3cf2152
commit
6e24973d7a
9 changed files with 72 additions and 51 deletions
36
lib/debug-artifacts.js
generated
36
lib/debug-artifacts.js
generated
|
|
@ -49,11 +49,11 @@ function sanitizeArtifactName(name) {
|
|||
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
||||
* environment variable is set
|
||||
*/
|
||||
async function uploadCombinedSarifArtifacts() {
|
||||
async function uploadCombinedSarifArtifacts(logger) {
|
||||
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") {
|
||||
core.info("Uploading available combined SARIF files as Actions debugging artifact...");
|
||||
logger.info("Uploading available combined SARIF files as Actions debugging artifact...");
|
||||
const baseTempDir = path.resolve(tempDir, "combined-sarif");
|
||||
const toUpload = [];
|
||||
if (fs.existsSync(baseTempDir)) {
|
||||
|
|
@ -67,9 +67,12 @@ async function uploadCombinedSarifArtifacts() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (toUpload.length > 0) {
|
||||
try {
|
||||
await uploadDebugArtifacts(toUpload, baseTempDir, "combined-sarif-artifacts");
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
@ -126,8 +129,8 @@ async function tryBundleDatabase(config, language, logger) {
|
|||
* Logs and suppresses any errors that occur.
|
||||
*/
|
||||
async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
||||
const filesToUpload = [];
|
||||
try {
|
||||
const filesToUpload = [];
|
||||
for (const language of config.languages) {
|
||||
await (0, logging_1.withGroup)(`Uploading debug artifacts for ${language}`, async () => {
|
||||
logger.info("Preparing SARIF result debug artifact...");
|
||||
|
|
@ -159,8 +162,13 @@ async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
|||
}
|
||||
});
|
||||
}
|
||||
logger.info("Uploading debug artifacts...");
|
||||
await uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName);
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to prepare debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await (0, logging_1.withGroup)("Uploading debug artifacts", async () => uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName));
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
|
|
@ -181,17 +189,11 @@ 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.");
|
||||
}
|
||||
}
|
||||
try {
|
||||
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,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
// A failure to upload debug artifacts should not fail the entire action.
|
||||
core.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(e)}`);
|
||||
}
|
||||
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,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue