mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Move .sarif predicates into UploadTarget instances and rename
This commit is contained in:
16
lib/upload-lib.js
generated
16
lib/upload-lib.js
generated
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.defaultIsSarif = exports.qualityIsSarif = exports.SARIF_UPLOAD_ENDPOINT = void 0;
|
exports.InvalidSarifUploadError = exports.CodeQualityTarget = exports.CodeScanningTarget = exports.SARIF_UPLOAD_ENDPOINT = void 0;
|
||||||
exports.shouldShowCombineSarifFilesDeprecationWarning = shouldShowCombineSarifFilesDeprecationWarning;
|
exports.shouldShowCombineSarifFilesDeprecationWarning = shouldShowCombineSarifFilesDeprecationWarning;
|
||||||
exports.populateRunAutomationDetails = populateRunAutomationDetails;
|
exports.populateRunAutomationDetails = populateRunAutomationDetails;
|
||||||
exports.findSarifFilesInDir = findSarifFilesInDir;
|
exports.findSarifFilesInDir = findSarifFilesInDir;
|
||||||
@@ -282,13 +282,9 @@ async function uploadPayload(payload, repositoryNwo, logger, target = SARIF_UPLO
|
|||||||
throw (0, api_client_1.wrapApiConfigurationError)(e);
|
throw (0, api_client_1.wrapApiConfigurationError)(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const qualityIsSarif = (name) => name.endsWith(".quality.sarif");
|
|
||||||
exports.qualityIsSarif = qualityIsSarif;
|
|
||||||
const defaultIsSarif = (name) => name.endsWith(".sarif") && !(0, exports.qualityIsSarif)(name);
|
|
||||||
exports.defaultIsSarif = defaultIsSarif;
|
|
||||||
// Recursively walks a directory and returns all SARIF files it finds.
|
// Recursively walks a directory and returns all SARIF files it finds.
|
||||||
// Does not follow symlinks.
|
// Does not follow symlinks.
|
||||||
function findSarifFilesInDir(sarifPath, isSarif = exports.defaultIsSarif) {
|
function findSarifFilesInDir(sarifPath, isSarif = exports.CodeScanningTarget.sarifPredicate) {
|
||||||
const sarifFiles = [];
|
const sarifFiles = [];
|
||||||
const walkSarifFiles = (dir) => {
|
const walkSarifFiles = (dir) => {
|
||||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
@@ -304,7 +300,7 @@ function findSarifFilesInDir(sarifPath, isSarif = exports.defaultIsSarif) {
|
|||||||
walkSarifFiles(sarifPath);
|
walkSarifFiles(sarifPath);
|
||||||
return sarifFiles;
|
return sarifFiles;
|
||||||
}
|
}
|
||||||
function getSarifFilePaths(sarifPath, isSarif = exports.defaultIsSarif) {
|
function getSarifFilePaths(sarifPath, isSarif = exports.CodeScanningTarget.sarifPredicate) {
|
||||||
if (!fs.existsSync(sarifPath)) {
|
if (!fs.existsSync(sarifPath)) {
|
||||||
// This is always a configuration error, even for first-party runs.
|
// This is always a configuration error, even for first-party runs.
|
||||||
throw new util_1.ConfigurationError(`Path does not exist: ${sarifPath}`);
|
throw new util_1.ConfigurationError(`Path does not exist: ${sarifPath}`);
|
||||||
@@ -425,14 +421,14 @@ function buildPayload(commitOid, ref, analysisKey, analysisName, zippedSarif, wo
|
|||||||
exports.CodeScanningTarget = {
|
exports.CodeScanningTarget = {
|
||||||
name: "code scanning",
|
name: "code scanning",
|
||||||
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
||||||
sarifFilter: exports.defaultIsSarif,
|
sarifPredicate: (name) => name.endsWith(".sarif") && !exports.CodeQualityTarget.sarifPredicate(name),
|
||||||
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
||||||
};
|
};
|
||||||
// Represents the Code Quality upload target.
|
// Represents the Code Quality upload target.
|
||||||
exports.CodeQualityTarget = {
|
exports.CodeQualityTarget = {
|
||||||
name: "code quality",
|
name: "code quality",
|
||||||
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
||||||
sarifFilter: exports.qualityIsSarif,
|
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
|
||||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -440,7 +436,7 @@ exports.CodeQualityTarget = {
|
|||||||
* to.
|
* to.
|
||||||
*/
|
*/
|
||||||
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget = exports.CodeScanningTarget) {
|
async function uploadFiles(inputSarifPath, checkoutPath, category, features, logger, uploadTarget = exports.CodeScanningTarget) {
|
||||||
const sarifPaths = getSarifFilePaths(inputSarifPath, uploadTarget.sarifFilter);
|
const sarifPaths = getSarifFilePaths(inputSarifPath, uploadTarget.sarifPredicate);
|
||||||
return uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget);
|
return uploadSpecifiedFiles(sarifPaths, checkoutPath, category, features, logger, uploadTarget);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
2
lib/upload-lib.test.js
generated
2
lib/upload-lib.test.js
generated
@@ -101,7 +101,7 @@ ava_1.default.beforeEach(() => {
|
|||||||
path.join(tmpDir, "dir1", "d.sarif"),
|
path.join(tmpDir, "dir1", "d.sarif"),
|
||||||
path.join(tmpDir, "dir1", "dir2", "e.sarif"),
|
path.join(tmpDir, "dir1", "dir2", "e.sarif"),
|
||||||
]);
|
]);
|
||||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(tmpDir, uploadLib.qualityIsSarif);
|
const qualitySarifFiles = uploadLib.findSarifFilesInDir(tmpDir, uploadLib.CodeQualityTarget.sarifPredicate);
|
||||||
t.deepEqual(qualitySarifFiles, [
|
t.deepEqual(qualitySarifFiles, [
|
||||||
path.join(tmpDir, "a.quality.sarif"),
|
path.join(tmpDir, "a.quality.sarif"),
|
||||||
path.join(tmpDir, "dir1", "b.quality.sarif"),
|
path.join(tmpDir, "dir1", "b.quality.sarif"),
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -137,7 +137,7 @@ test("finding SARIF files", async (t) => {
|
|||||||
|
|
||||||
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
|
const qualitySarifFiles = uploadLib.findSarifFilesInDir(
|
||||||
tmpDir,
|
tmpDir,
|
||||||
uploadLib.qualityIsSarif,
|
uploadLib.CodeQualityTarget.sarifPredicate,
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(qualitySarifFiles, [
|
t.deepEqual(qualitySarifFiles, [
|
||||||
|
|||||||
@@ -380,15 +380,11 @@ export interface UploadResult {
|
|||||||
sarifID: string;
|
sarifID: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
|
|
||||||
export const defaultIsSarif = (name: string) =>
|
|
||||||
name.endsWith(".sarif") && !qualityIsSarif(name);
|
|
||||||
|
|
||||||
// Recursively walks a directory and returns all SARIF files it finds.
|
// Recursively walks a directory and returns all SARIF files it finds.
|
||||||
// Does not follow symlinks.
|
// Does not follow symlinks.
|
||||||
export function findSarifFilesInDir(
|
export function findSarifFilesInDir(
|
||||||
sarifPath: string,
|
sarifPath: string,
|
||||||
isSarif: (name: string) => boolean = defaultIsSarif,
|
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
|
||||||
): string[] {
|
): string[] {
|
||||||
const sarifFiles: string[] = [];
|
const sarifFiles: string[] = [];
|
||||||
const walkSarifFiles = (dir: string) => {
|
const walkSarifFiles = (dir: string) => {
|
||||||
@@ -407,7 +403,7 @@ export function findSarifFilesInDir(
|
|||||||
|
|
||||||
export function getSarifFilePaths(
|
export function getSarifFilePaths(
|
||||||
sarifPath: string,
|
sarifPath: string,
|
||||||
isSarif: (name: string) => boolean = defaultIsSarif,
|
isSarif: (name: string) => boolean = CodeScanningTarget.sarifPredicate,
|
||||||
) {
|
) {
|
||||||
if (!fs.existsSync(sarifPath)) {
|
if (!fs.existsSync(sarifPath)) {
|
||||||
// This is always a configuration error, even for first-party runs.
|
// This is always a configuration error, even for first-party runs.
|
||||||
@@ -585,7 +581,7 @@ export function buildPayload(
|
|||||||
export interface UploadTarget {
|
export interface UploadTarget {
|
||||||
name: string;
|
name: string;
|
||||||
target: SARIF_UPLOAD_ENDPOINT;
|
target: SARIF_UPLOAD_ENDPOINT;
|
||||||
sarifFilter: (name: string) => boolean;
|
sarifPredicate: (name: string) => boolean;
|
||||||
sentinelPrefix: string;
|
sentinelPrefix: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,7 +589,7 @@ export interface UploadTarget {
|
|||||||
export const CodeScanningTarget: UploadTarget = {
|
export const CodeScanningTarget: UploadTarget = {
|
||||||
name: "code scanning",
|
name: "code scanning",
|
||||||
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
target: SARIF_UPLOAD_ENDPOINT.CODE_SCANNING_UPLOAD_TARGET,
|
||||||
sarifFilter: defaultIsSarif,
|
sarifPredicate: (name) => name.endsWith(".sarif") && !CodeQualityTarget.sarifPredicate(name),
|
||||||
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
sentinelPrefix: "CODEQL_UPLOAD_SARIF_",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -601,7 +597,7 @@ export const CodeScanningTarget: UploadTarget = {
|
|||||||
export const CodeQualityTarget: UploadTarget = {
|
export const CodeQualityTarget: UploadTarget = {
|
||||||
name: "code quality",
|
name: "code quality",
|
||||||
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
target: SARIF_UPLOAD_ENDPOINT.CODE_QUALITY_UPLOAD_TARGET,
|
||||||
sarifFilter: qualityIsSarif,
|
sarifPredicate: (name) => name.endsWith(".quality.sarif"),
|
||||||
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
sentinelPrefix: "CODEQL_UPLOAD_QUALITY_SARIF_",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -619,7 +615,7 @@ export async function uploadFiles(
|
|||||||
): Promise<UploadResult> {
|
): Promise<UploadResult> {
|
||||||
const sarifPaths = getSarifFilePaths(
|
const sarifPaths = getSarifFilePaths(
|
||||||
inputSarifPath,
|
inputSarifPath,
|
||||||
uploadTarget.sarifFilter,
|
uploadTarget.sarifPredicate,
|
||||||
);
|
);
|
||||||
|
|
||||||
return uploadSpecifiedFiles(
|
return uploadSpecifiedFiles(
|
||||||
|
|||||||
Reference in New Issue
Block a user