mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
build: refresh js files
This commit is contained in:
4
lib/analyze.js
generated
4
lib/analyze.js
generated
@@ -55,6 +55,7 @@ const api_client_1 = require("./api-client");
|
|||||||
const autobuild_1 = require("./autobuild");
|
const autobuild_1 = require("./autobuild");
|
||||||
const codeql_1 = require("./codeql");
|
const codeql_1 = require("./codeql");
|
||||||
const diagnostics_1 = require("./diagnostics");
|
const diagnostics_1 = require("./diagnostics");
|
||||||
|
const diff_filtering_utils_1 = require("./diff-filtering-utils");
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
const feature_flags_1 = require("./feature-flags");
|
const feature_flags_1 = require("./feature-flags");
|
||||||
const languages_1 = require("./languages");
|
const languages_1 = require("./languages");
|
||||||
@@ -368,6 +369,9 @@ extensions:
|
|||||||
const extensionFilePath = path.join(diffRangeDir, "pr-diff-range.yml");
|
const extensionFilePath = path.join(diffRangeDir, "pr-diff-range.yml");
|
||||||
fs.writeFileSync(extensionFilePath, extensionContents);
|
fs.writeFileSync(extensionFilePath, extensionContents);
|
||||||
logger.debug(`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`);
|
logger.debug(`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`);
|
||||||
|
// Write the diff ranges to a JSON file, for action-side alert filtering by the
|
||||||
|
// upload-lib module.
|
||||||
|
(0, diff_filtering_utils_1.writeDiffRangesJsonFile)(logger, ranges);
|
||||||
return diffRangeDir;
|
return diffRangeDir;
|
||||||
}
|
}
|
||||||
// Runs queries and creates sarif files in the given folder
|
// Runs queries and creates sarif files in the given folder
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
60
lib/diff-filtering-utils.js
generated
Normal file
60
lib/diff-filtering-utils.js
generated
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
"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 () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.writeDiffRangesJsonFile = writeDiffRangesJsonFile;
|
||||||
|
exports.readDiffRangesJsonFile = readDiffRangesJsonFile;
|
||||||
|
const fs = __importStar(require("fs"));
|
||||||
|
const path = __importStar(require("path"));
|
||||||
|
const actionsUtil = __importStar(require("./actions-util"));
|
||||||
|
function getDiffRangesJsonFilePath() {
|
||||||
|
return path.join(actionsUtil.getTemporaryDirectory(), "pr-diff-range.json");
|
||||||
|
}
|
||||||
|
function writeDiffRangesJsonFile(logger, ranges) {
|
||||||
|
const jsonContents = JSON.stringify(ranges, null, 2);
|
||||||
|
const jsonFilePath = getDiffRangesJsonFilePath();
|
||||||
|
fs.writeFileSync(jsonFilePath, jsonContents);
|
||||||
|
logger.debug(`Wrote pr-diff-range JSON file to ${jsonFilePath}:\n${jsonContents}`);
|
||||||
|
}
|
||||||
|
function readDiffRangesJsonFile(logger) {
|
||||||
|
const jsonFilePath = getDiffRangesJsonFilePath();
|
||||||
|
if (!fs.existsSync(jsonFilePath)) {
|
||||||
|
logger.debug(`Diff ranges JSON file does not exist at ${jsonFilePath}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const jsonContents = fs.readFileSync(jsonFilePath, "utf8");
|
||||||
|
logger.debug(`Read pr-diff-range JSON file from ${jsonFilePath}:\n${jsonContents}`);
|
||||||
|
return JSON.parse(jsonContents);
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=diff-filtering-utils.js.map
|
||||||
1
lib/diff-filtering-utils.js.map
Normal file
1
lib/diff-filtering-utils.js.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"diff-filtering-utils.js","sourceRoot":"","sources":["../src/diff-filtering-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,0DAUC;AAED,wDAaC;AAzCD,uCAAyB;AACzB,2CAA6B;AAE7B,4DAA8C;AAS9C,SAAS,yBAAyB;IAChC,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE,EAAE,oBAAoB,CAAC,CAAC;AAC9E,CAAC;AAED,SAAgB,uBAAuB,CACrC,MAAc,EACd,MAAwB;IAExB,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,yBAAyB,EAAE,CAAC;IACjD,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,CACV,oCAAoC,YAAY,MAAM,YAAY,EAAE,CACrE,CAAC;AACJ,CAAC;AAED,SAAgB,sBAAsB,CACpC,MAAc;IAEd,MAAM,YAAY,GAAG,yBAAyB,EAAE,CAAC;IACjD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,KAAK,CAAC,2CAA2C,YAAY,EAAE,CAAC,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,CAAC,KAAK,CACV,qCAAqC,YAAY,MAAM,YAAY,EAAE,CACtE,CAAC;IACF,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAqB,CAAC;AACtD,CAAC"}
|
||||||
41
lib/upload-lib.js
generated
41
lib/upload-lib.js
generated
@@ -58,6 +58,7 @@ const api = __importStar(require("./api-client"));
|
|||||||
const api_client_1 = require("./api-client");
|
const api_client_1 = require("./api-client");
|
||||||
const codeql_1 = require("./codeql");
|
const codeql_1 = require("./codeql");
|
||||||
const config_utils_1 = require("./config-utils");
|
const config_utils_1 = require("./config-utils");
|
||||||
|
const diff_filtering_utils_1 = require("./diff-filtering-utils");
|
||||||
const environment_1 = require("./environment");
|
const environment_1 = require("./environment");
|
||||||
const fingerprints = __importStar(require("./fingerprints"));
|
const fingerprints = __importStar(require("./fingerprints"));
|
||||||
const gitUtils = __importStar(require("./git-utils"));
|
const gitUtils = __importStar(require("./git-utils"));
|
||||||
@@ -412,6 +413,7 @@ async function uploadFiles(sarifPath, checkoutPath, category, features, logger)
|
|||||||
validateSarifFileSchema(file, logger);
|
validateSarifFileSchema(file, logger);
|
||||||
}
|
}
|
||||||
let sarif = await combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger);
|
let sarif = await combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger);
|
||||||
|
sarif = filterAlertsByDiffRange(logger, sarif);
|
||||||
sarif = await fingerprints.addFingerprints(sarif, checkoutPath, logger);
|
sarif = await fingerprints.addFingerprints(sarif, checkoutPath, logger);
|
||||||
const analysisKey = await api.getAnalysisKey();
|
const analysisKey = await api.getAnalysisKey();
|
||||||
const environment = actionsUtil.getRequiredInput("matrix");
|
const environment = actionsUtil.getRequiredInput("matrix");
|
||||||
@@ -607,4 +609,43 @@ class InvalidSarifUploadError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.InvalidSarifUploadError = InvalidSarifUploadError;
|
exports.InvalidSarifUploadError = InvalidSarifUploadError;
|
||||||
|
function filterAlertsByDiffRange(logger, sarif) {
|
||||||
|
const diffRanges = (0, diff_filtering_utils_1.readDiffRangesJsonFile)(logger);
|
||||||
|
if (!diffRanges?.length) {
|
||||||
|
return sarif;
|
||||||
|
}
|
||||||
|
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
|
||||||
|
for (const run of sarif.runs) {
|
||||||
|
if (run.results) {
|
||||||
|
run.results = run.results.filter((result) => {
|
||||||
|
const locations = [
|
||||||
|
...(result.locations || []).map((loc) => loc.physicalLocation),
|
||||||
|
...(result.relatedLocations || []).map((loc) => loc.physicalLocation),
|
||||||
|
];
|
||||||
|
return locations.some((physicalLocation) => {
|
||||||
|
const locationUri = physicalLocation?.artifactLocation?.uri;
|
||||||
|
const locationStartLine = physicalLocation?.region?.startLine;
|
||||||
|
if (!locationUri || locationStartLine === undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// CodeQL always uses forward slashes as the path separator, so on Windows we
|
||||||
|
// need to replace any backslashes with forward slashes.
|
||||||
|
const locationPath = path
|
||||||
|
.join(checkoutPath, locationUri)
|
||||||
|
.replaceAll(path.sep, "/");
|
||||||
|
// Alert filtering here replicates the same behavior as the restrictAlertsTo
|
||||||
|
// extensible predicate in CodeQL. See the restrictAlertsTo documentation
|
||||||
|
// https://codeql.github.com/codeql-standard-libraries/csharp/codeql/util/AlertFiltering.qll/predicate.AlertFiltering$restrictAlertsTo.3.html
|
||||||
|
// for more details, such as why the filtering applies only to the first line
|
||||||
|
// of an alert location.
|
||||||
|
return diffRanges.some((range) => range.path === locationPath &&
|
||||||
|
((range.startLine <= locationStartLine &&
|
||||||
|
range.endLine >= locationStartLine) ||
|
||||||
|
(range.startLine === 0 && range.endLine === 0)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sarif;
|
||||||
|
}
|
||||||
//# sourceMappingURL=upload-lib.js.map
|
//# sourceMappingURL=upload-lib.js.map
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user