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
4
lib/analyze-action-post.js
generated
4
lib/analyze-action-post.js
generated
|
|
@ -31,13 +31,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
|
const logging_1 = require("./logging");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
async function runWrapper() {
|
async function runWrapper() {
|
||||||
try {
|
try {
|
||||||
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
// Upload SARIF artifacts if we determine that this is a first-party analysis run.
|
// Upload SARIF artifacts if we determine that this is a first-party analysis run.
|
||||||
// For third-party runs, this artifact will be uploaded in the `upload-sarif-post` step.
|
// For third-party runs, this artifact will be uploaded in the `upload-sarif-post` step.
|
||||||
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
||||||
await debugArtifacts.uploadCombinedSarifArtifacts();
|
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"analyze-action-post.js","sourceRoot":"","sources":["../src/analyze-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,kEAAoD;AACpD,+CAAuC;AACvC,iCAAyC;AAEzC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,kFAAkF;QAClF,wFAAwF;QACxF,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,cAAc,CAAC,4BAA4B,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,oCAAoC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAC7D,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,kEAAoD;AACpD,+CAAuC;AACvC,uCAAwD;AACxD,iCAAyC;AAEzC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;QAElC,kFAAkF;QAClF,wFAAwF;QACxF,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,IAAA,mBAAS,EAAC,yCAAyC,EAAE,GAAG,EAAE,CAC9D,cAAc,CAAC,4BAA4B,CAAC,MAAM,CAAC,CACpD,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,oCAAoC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
|
||||||
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
|
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
||||||
* environment variable is set
|
* environment variable is set
|
||||||
*/
|
*/
|
||||||
async function uploadCombinedSarifArtifacts() {
|
async function uploadCombinedSarifArtifacts(logger) {
|
||||||
const tempDir = (0, actions_util_1.getTemporaryDirectory)();
|
const tempDir = (0, actions_util_1.getTemporaryDirectory)();
|
||||||
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
||||||
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
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 baseTempDir = path.resolve(tempDir, "combined-sarif");
|
||||||
const toUpload = [];
|
const toUpload = [];
|
||||||
if (fs.existsSync(baseTempDir)) {
|
if (fs.existsSync(baseTempDir)) {
|
||||||
|
|
@ -67,9 +67,12 @@ async function uploadCombinedSarifArtifacts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toUpload.length > 0) {
|
try {
|
||||||
await uploadDebugArtifacts(toUpload, baseTempDir, "combined-sarif-artifacts");
|
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.
|
* Logs and suppresses any errors that occur.
|
||||||
*/
|
*/
|
||||||
async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
async function tryUploadAllAvailableDebugArtifacts(config, logger) {
|
||||||
|
const filesToUpload = [];
|
||||||
try {
|
try {
|
||||||
const filesToUpload = [];
|
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
await (0, logging_1.withGroup)(`Uploading debug artifacts for ${language}`, async () => {
|
await (0, logging_1.withGroup)(`Uploading debug artifacts for ${language}`, async () => {
|
||||||
logger.info("Preparing SARIF result debug artifact...");
|
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) {
|
catch (e) {
|
||||||
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.getErrorMessage)(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.");
|
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), {
|
||||||
await artifact.create().uploadArtifact(sanitizeArtifactName(`${artifactName}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir), {
|
continueOnError: true,
|
||||||
continueOnError: true,
|
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
||||||
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
retentionDays: 7,
|
||||||
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)}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
* If a database has not been finalized, we cannot run the `codeql database bundle`
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
4
lib/upload-sarif-action-post.js
generated
4
lib/upload-sarif-action-post.js
generated
|
|
@ -31,13 +31,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
const debugArtifacts = __importStar(require("./debug-artifacts"));
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
|
const logging_1 = require("./logging");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
async function runWrapper() {
|
async function runWrapper() {
|
||||||
try {
|
try {
|
||||||
|
const logger = (0, logging_1.getActionsLogger)();
|
||||||
// Upload SARIF artifacts if we determine that this is a third-party analysis run.
|
// Upload SARIF artifacts if we determine that this is a third-party analysis run.
|
||||||
// For first-party runs, this artifact will be uploaded in the `analyze-post` step.
|
// For first-party runs, this artifact will be uploaded in the `analyze-post` step.
|
||||||
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
|
if (process.env[environment_1.EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
|
||||||
await debugArtifacts.uploadCombinedSarifArtifacts();
|
await (0, logging_1.withGroup)("Uploading combined SARIF debug artifact", () => debugArtifacts.uploadCombinedSarifArtifacts(logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"upload-sarif-action-post.js","sourceRoot":"","sources":["../src/upload-sarif-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,kEAAoD;AACpD,+CAAuC;AACvC,iCAAyC;AAEzC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,kFAAkF;QAClF,mFAAmF;QACnF,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,cAAc,CAAC,4BAA4B,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,yCAAyC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
|
{"version":3,"file":"upload-sarif-action-post.js","sourceRoot":"","sources":["../src/upload-sarif-action-post.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,oDAAsC;AAEtC,kEAAoD;AACpD,+CAAuC;AACvC,uCAAwD;AACxD,iCAAyC;AAEzC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,0BAAgB,GAAE,CAAC;QAClC,kFAAkF;QAClF,mFAAmF;QACnF,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAM,CAAC,mBAAmB,CAAC,KAAK,MAAM,EAAE,CAAC;YACvD,MAAM,IAAA,mBAAS,EAAC,yCAAyC,EAAE,GAAG,EAAE,CAC9D,cAAc,CAAC,4BAA4B,CAAC,MAAM,CAAC,CACpD,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CACZ,yCAAyC,IAAA,sBAAe,EAAC,KAAK,CAAC,EAAE,CAClE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"}
|
||||||
|
|
@ -7,14 +7,19 @@ import * as core from "@actions/core";
|
||||||
|
|
||||||
import * as debugArtifacts from "./debug-artifacts";
|
import * as debugArtifacts from "./debug-artifacts";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
|
import { getActionsLogger, withGroup } from "./logging";
|
||||||
import { getErrorMessage } from "./util";
|
import { getErrorMessage } from "./util";
|
||||||
|
|
||||||
async function runWrapper() {
|
async function runWrapper() {
|
||||||
try {
|
try {
|
||||||
|
const logger = getActionsLogger();
|
||||||
|
|
||||||
// Upload SARIF artifacts if we determine that this is a first-party analysis run.
|
// Upload SARIF artifacts if we determine that this is a first-party analysis run.
|
||||||
// For third-party runs, this artifact will be uploaded in the `upload-sarif-post` step.
|
// For third-party runs, this artifact will be uploaded in the `upload-sarif-post` step.
|
||||||
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] === "true") {
|
||||||
await debugArtifacts.uploadCombinedSarifArtifacts();
|
await withGroup("Uploading combined SARIF debug artifact", () =>
|
||||||
|
debugArtifacts.uploadCombinedSarifArtifacts(logger),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,12 @@ export function sanitizeArtifactName(name: string): string {
|
||||||
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
* Upload Actions SARIF artifacts for debugging when CODEQL_ACTION_DEBUG_COMBINED_SARIF
|
||||||
* environment variable is set
|
* environment variable is set
|
||||||
*/
|
*/
|
||||||
export async function uploadCombinedSarifArtifacts() {
|
export async function uploadCombinedSarifArtifacts(logger: Logger) {
|
||||||
const tempDir = getTemporaryDirectory();
|
const tempDir = getTemporaryDirectory();
|
||||||
|
|
||||||
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
// Upload Actions SARIF artifacts for debugging when environment variable is set
|
||||||
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
if (process.env["CODEQL_ACTION_DEBUG_COMBINED_SARIF"] === "true") {
|
||||||
core.info(
|
logger.info(
|
||||||
"Uploading available combined SARIF files as Actions debugging artifact...",
|
"Uploading available combined SARIF files as Actions debugging artifact...",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -56,12 +56,18 @@ export async function uploadCombinedSarifArtifacts() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toUpload.length > 0) {
|
try {
|
||||||
await uploadDebugArtifacts(
|
await uploadDebugArtifacts(
|
||||||
toUpload,
|
toUpload,
|
||||||
baseTempDir,
|
baseTempDir,
|
||||||
"combined-sarif-artifacts",
|
"combined-sarif-artifacts",
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warning(
|
||||||
|
`Failed to upload combined SARIF files as Actions debugging artifact. Reason: ${getErrorMessage(
|
||||||
|
e,
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,9 +154,8 @@ export async function tryUploadAllAvailableDebugArtifacts(
|
||||||
config: Config,
|
config: Config,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
) {
|
) {
|
||||||
|
const filesToUpload: string[] = [];
|
||||||
try {
|
try {
|
||||||
const filesToUpload: string[] = [];
|
|
||||||
|
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
await withGroup(`Uploading debug artifacts for ${language}`, async () => {
|
await withGroup(`Uploading debug artifacts for ${language}`, async () => {
|
||||||
logger.info("Preparing SARIF result debug artifact...");
|
logger.info("Preparing SARIF result debug artifact...");
|
||||||
|
|
@ -196,12 +201,20 @@ export async function tryUploadAllAvailableDebugArtifacts(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.warning(
|
||||||
|
`Failed to prepare debug artifacts. Reason: ${getErrorMessage(e)}`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Uploading debug artifacts...");
|
try {
|
||||||
await uploadDebugArtifacts(
|
await withGroup("Uploading debug artifacts", async () =>
|
||||||
filesToUpload,
|
uploadDebugArtifacts(
|
||||||
config.dbLocation,
|
filesToUpload,
|
||||||
config.debugArtifactName,
|
config.dbLocation,
|
||||||
|
config.debugArtifactName,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|
@ -233,23 +246,16 @@ export async function uploadDebugArtifacts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await artifact.create().uploadArtifact(
|
||||||
await artifact.create().uploadArtifact(
|
sanitizeArtifactName(`${artifactName}${suffix}`),
|
||||||
sanitizeArtifactName(`${artifactName}${suffix}`),
|
toUpload.map((file) => path.normalize(file)),
|
||||||
toUpload.map((file) => path.normalize(file)),
|
path.normalize(rootDir),
|
||||||
path.normalize(rootDir),
|
{
|
||||||
{
|
continueOnError: true,
|
||||||
continueOnError: true,
|
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
||||||
// ensure we don't keep the debug artifacts around for too long since they can be large.
|
retentionDays: 7,
|
||||||
retentionDays: 7,
|
},
|
||||||
},
|
);
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
// A failure to upload debug artifacts should not fail the entire action.
|
|
||||||
core.warning(
|
|
||||||
`Failed to upload debug artifacts. Reason: ${getErrorMessage(e)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,18 @@ import * as core from "@actions/core";
|
||||||
|
|
||||||
import * as debugArtifacts from "./debug-artifacts";
|
import * as debugArtifacts from "./debug-artifacts";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
|
import { getActionsLogger, withGroup } from "./logging";
|
||||||
import { getErrorMessage } from "./util";
|
import { getErrorMessage } from "./util";
|
||||||
|
|
||||||
async function runWrapper() {
|
async function runWrapper() {
|
||||||
try {
|
try {
|
||||||
|
const logger = getActionsLogger();
|
||||||
// Upload SARIF artifacts if we determine that this is a third-party analysis run.
|
// Upload SARIF artifacts if we determine that this is a third-party analysis run.
|
||||||
// For first-party runs, this artifact will be uploaded in the `analyze-post` step.
|
// For first-party runs, this artifact will be uploaded in the `analyze-post` step.
|
||||||
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
|
if (process.env[EnvVar.INIT_ACTION_HAS_RUN] !== "true") {
|
||||||
await debugArtifacts.uploadCombinedSarifArtifacts();
|
await withGroup("Uploading combined SARIF debug artifact", () =>
|
||||||
|
debugArtifacts.uploadCombinedSarifArtifacts(logger),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue