Merge pull request #1610 from github/henrymercer/diagnostics-workaround-improvements
Follow-up improvements to the diagnostics workaround
This commit is contained in:
commit
bc0ed6a6c3
6 changed files with 35 additions and 27 deletions
8
lib/codeql.js
generated
8
lib/codeql.js
generated
|
|
@ -544,9 +544,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
|||
// capture stdout, which contains analysis summaries
|
||||
const returnState = await (0, toolrunner_error_catcher_1.toolrunnerErrorCatcher)(cmd, codeqlArgs, error_matcher_1.errorMatchers);
|
||||
if (shouldExportDiagnostics) {
|
||||
let sarif = JSON.parse(fs.readFileSync(codeqlOutputFile, "utf8"));
|
||||
sarif = util.fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
|
||||
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
|
||||
}
|
||||
return returnState.stdout;
|
||||
},
|
||||
|
|
@ -642,9 +640,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
|||
}
|
||||
await new toolrunner.ToolRunner(cmd, args).exec();
|
||||
// Fix invalid notifications in the SARIF file output by CodeQL.
|
||||
let sarif = JSON.parse(fs.readFileSync(intermediateSarifFile, "utf8"));
|
||||
sarif = util.fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
|
||||
util.fixInvalidNotificationsInFile(intermediateSarifFile, sarifFile, logger);
|
||||
},
|
||||
async diagnosticsExport(sarifFile, automationDetailsId, config, features) {
|
||||
const args = [
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
16
lib/util.js
generated
16
lib/util.js
generated
|
|
@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.isInTestMode = exports.getMlPoweredJsQueriesStatus = exports.getMlPoweredJsQueriesPack = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.UserError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
|
||||
exports.fixInvalidNotificationsInFile = exports.fixInvalidNotifications = exports.parseMatrixInput = exports.isHostedRunner = exports.checkForTimeout = exports.withTimeout = exports.tryGetFolderBytes = exports.listFolder = exports.doesDirectoryExist = exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.isInTestMode = exports.getMlPoweredJsQueriesStatus = exports.getMlPoweredJsQueriesPack = exports.ML_POWERED_JS_QUERIES_PACK_NAME = exports.supportExpectDiscardedCache = exports.isGoodVersion = exports.delay = exports.bundleDb = exports.codeQlVersionAbove = exports.getCachedCodeQlVersion = exports.cacheCodeQlVersion = exports.isHTTPError = exports.UserError = exports.HTTPError = exports.getRequiredEnvParam = exports.initializeEnvironment = exports.assertNever = exports.apiVersionInRange = exports.DisallowedAPIVersionReason = exports.checkGitHubVersionInRange = exports.getGitHubVersion = exports.GitHubVariant = exports.parseGitHubUrl = exports.getCodeQLDatabasePath = exports.getThreadsFlag = exports.getThreadsFlagValue = exports.getAddSnippetsFlag = exports.getMemoryFlag = exports.getMemoryFlagValue = exports.withTmpDir = exports.getToolNames = exports.getExtraOptionsEnvParam = exports.DEFAULT_DEBUG_DATABASE_NAME = exports.DEFAULT_DEBUG_ARTIFACT_NAME = exports.GITHUB_DOTCOM_URL = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
|
|
@ -676,7 +676,7 @@ function fixInvalidNotifications(sarif, logger) {
|
|||
`${shared_environment_1.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`);
|
||||
return sarif;
|
||||
}
|
||||
if (!(sarif.runs instanceof Array)) {
|
||||
if (!Array.isArray(sarif.runs)) {
|
||||
return sarif;
|
||||
}
|
||||
// Ensure that the array of locations for each SARIF notification contains unique locations.
|
||||
|
|
@ -687,19 +687,19 @@ function fixInvalidNotifications(sarif, logger) {
|
|||
...sarif,
|
||||
runs: sarif.runs.map((run) => {
|
||||
if (run.tool?.driver?.name !== "CodeQL" ||
|
||||
!(run.invocations instanceof Array)) {
|
||||
!Array.isArray(run.invocations)) {
|
||||
return run;
|
||||
}
|
||||
return {
|
||||
...run,
|
||||
invocations: run.invocations.map((invocation) => {
|
||||
if (!(invocation.toolExecutionNotifications instanceof Array)) {
|
||||
if (!Array.isArray(invocation.toolExecutionNotifications)) {
|
||||
return invocation;
|
||||
}
|
||||
return {
|
||||
...invocation,
|
||||
toolExecutionNotifications: invocation.toolExecutionNotifications.map((notification) => {
|
||||
if (!(notification.locations instanceof Array)) {
|
||||
if (!Array.isArray(notification.locations)) {
|
||||
return notification;
|
||||
}
|
||||
const newLocations = removeDuplicateLocations(notification.locations);
|
||||
|
|
@ -722,4 +722,10 @@ function fixInvalidNotifications(sarif, logger) {
|
|||
return newSarif;
|
||||
}
|
||||
exports.fixInvalidNotifications = fixInvalidNotifications;
|
||||
function fixInvalidNotificationsInFile(inputPath, outputPath, logger) {
|
||||
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8"));
|
||||
sarif = fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(outputPath, JSON.stringify(sarif));
|
||||
}
|
||||
exports.fixInvalidNotificationsInFile = fixInvalidNotificationsInFile;
|
||||
//# sourceMappingURL=util.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -923,11 +923,7 @@ export async function getCodeQLForCmd(
|
|||
);
|
||||
|
||||
if (shouldExportDiagnostics) {
|
||||
let sarif = JSON.parse(
|
||||
fs.readFileSync(codeqlOutputFile, "utf8")
|
||||
) as util.SarifFile;
|
||||
sarif = util.fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
|
||||
util.fixInvalidNotificationsInFile(codeqlOutputFile, sarifFile, logger);
|
||||
}
|
||||
|
||||
return returnState.stdout;
|
||||
|
|
@ -1050,11 +1046,11 @@ export async function getCodeQLForCmd(
|
|||
await new toolrunner.ToolRunner(cmd, args).exec();
|
||||
|
||||
// Fix invalid notifications in the SARIF file output by CodeQL.
|
||||
let sarif = JSON.parse(
|
||||
fs.readFileSync(intermediateSarifFile, "utf8")
|
||||
) as util.SarifFile;
|
||||
sarif = util.fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(sarifFile, JSON.stringify(sarif));
|
||||
util.fixInvalidNotificationsInFile(
|
||||
intermediateSarifFile,
|
||||
sarifFile,
|
||||
logger
|
||||
);
|
||||
},
|
||||
async diagnosticsExport(
|
||||
sarifFile: string,
|
||||
|
|
|
|||
18
src/util.ts
18
src/util.ts
|
|
@ -823,7 +823,7 @@ export function fixInvalidNotifications(
|
|||
);
|
||||
return sarif;
|
||||
}
|
||||
if (!(sarif.runs instanceof Array)) {
|
||||
if (!Array.isArray(sarif.runs)) {
|
||||
return sarif;
|
||||
}
|
||||
|
||||
|
|
@ -837,21 +837,21 @@ export function fixInvalidNotifications(
|
|||
runs: sarif.runs.map((run) => {
|
||||
if (
|
||||
run.tool?.driver?.name !== "CodeQL" ||
|
||||
!(run.invocations instanceof Array)
|
||||
!Array.isArray(run.invocations)
|
||||
) {
|
||||
return run;
|
||||
}
|
||||
return {
|
||||
...run,
|
||||
invocations: run.invocations.map((invocation) => {
|
||||
if (!(invocation.toolExecutionNotifications instanceof Array)) {
|
||||
if (!Array.isArray(invocation.toolExecutionNotifications)) {
|
||||
return invocation;
|
||||
}
|
||||
return {
|
||||
...invocation,
|
||||
toolExecutionNotifications:
|
||||
invocation.toolExecutionNotifications.map((notification) => {
|
||||
if (!(notification.locations instanceof Array)) {
|
||||
if (!Array.isArray(notification.locations)) {
|
||||
return notification;
|
||||
}
|
||||
const newLocations = removeDuplicateLocations(
|
||||
|
|
@ -878,3 +878,13 @@ export function fixInvalidNotifications(
|
|||
}
|
||||
return newSarif;
|
||||
}
|
||||
|
||||
export function fixInvalidNotificationsInFile(
|
||||
inputPath: string,
|
||||
outputPath: string,
|
||||
logger: Logger
|
||||
): void {
|
||||
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile;
|
||||
sarif = fixInvalidNotifications(sarif, logger);
|
||||
fs.writeFileSync(outputPath, JSON.stringify(sarif));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue