introduce inputs.threads flag to analyze action
This commit is contained in:
parent
74f864bee1
commit
d55f711b71
7 changed files with 165 additions and 13 deletions
|
|
@ -4,6 +4,7 @@ author: 'GitHub'
|
|||
inputs:
|
||||
check_name:
|
||||
description: The name of the check run to add text to.
|
||||
required: false
|
||||
output:
|
||||
description: The path of the directory in which to save the SARIF results
|
||||
required: false
|
||||
|
|
@ -11,10 +12,14 @@ inputs:
|
|||
upload:
|
||||
description: Upload the SARIF file
|
||||
required: false
|
||||
default: true
|
||||
default: "true"
|
||||
ram:
|
||||
description: Override the amount of memory in MB to be used by CodeQL. By default, almost all the memory of the machine is used.
|
||||
required: false
|
||||
threads:
|
||||
description: The number of threads to be used by CodeQL.
|
||||
required: false
|
||||
default: "1"
|
||||
token:
|
||||
default: ${{ github.token }}
|
||||
matrix:
|
||||
|
|
|
|||
18
lib/finalize-db.js
generated
18
lib/finalize-db.js
generated
|
|
@ -54,6 +54,23 @@ function getMemoryFlag() {
|
|||
}
|
||||
return "--ram=" + Math.floor(memoryToUseMegaBytes);
|
||||
}
|
||||
exports.getMemoryFlag = getMemoryFlag;
|
||||
function getThreadsFlag() {
|
||||
let numThreads = 1;
|
||||
const numThreadsString = core.getInput("threads");
|
||||
if (numThreadsString) {
|
||||
numThreads = Number(numThreadsString);
|
||||
if (Number.isNaN(numThreads) || numThreads < 0) {
|
||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||
}
|
||||
const maxThreads = os.cpus().length;
|
||||
if (numThreads > maxThreads) {
|
||||
numThreads = maxThreads;
|
||||
}
|
||||
}
|
||||
return `--threads=${numThreads}`;
|
||||
}
|
||||
exports.getThreadsFlag = getThreadsFlag;
|
||||
async function createdDBForScannedLanguages(codeqlCmd, databaseFolder) {
|
||||
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
|
||||
if (scannedLanguages) {
|
||||
|
|
@ -164,6 +181,7 @@ async function runQueries(codeqlCmd, databaseFolder, sarifFolder, config) {
|
|||
'database',
|
||||
'analyze',
|
||||
getMemoryFlag(),
|
||||
getThreadsFlag(),
|
||||
path.join(databaseFolder, database),
|
||||
'--format=sarif-latest',
|
||||
'--output=' + sarifFile,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
53
lib/finalize-db.test.js
generated
Normal file
53
lib/finalize-db.test.js
generated
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const os = __importStar(require("os"));
|
||||
const finalize_db_1 = require("./finalize-db");
|
||||
ava_1.default('getMemoryFlag() should return the correct --ram flag', t => {
|
||||
const totalMem = os.totalmem() / (1024 * 1024);
|
||||
const tests = {
|
||||
"": `--ram=${totalMem - 256}`,
|
||||
"512": "--ram=512",
|
||||
};
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
process.env['INPUT_RAM'] = input;
|
||||
const flag = finalize_db_1.getMemoryFlag();
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
ava_1.default('getMemoryFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
process.env['INPUT_RAM'] = input;
|
||||
t.throws(finalize_db_1.getMemoryFlag);
|
||||
}
|
||||
});
|
||||
ava_1.default('getThreadsFlag() should return the correct --threads flag', t => {
|
||||
const numCpus = os.cpus().length;
|
||||
const tests = {
|
||||
"0": "--threads=0",
|
||||
"1": "--threads=1",
|
||||
[`${numCpus + 1}`]: `--threads=${numCpus}`
|
||||
};
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
const flag = finalize_db_1.getThreadsFlag();
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
ava_1.default('getThreadsFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
t.throws(finalize_db_1.getThreadsFlag);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=finalize-db.test.js.map
|
||||
1
lib/finalize-db.test.js.map
Normal file
1
lib/finalize-db.test.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"finalize-db.test.js","sourceRoot":"","sources":["../src/finalize-db.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AACvB,uCAAyB;AAEzB,+CAGuB;AAEvB,aAAI,CAAC,sDAAsD,EAAE,CAAC,CAAC,EAAE;IAE7D,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAE/C,MAAM,KAAK,GAAG;QACV,EAAE,EAAE,SAAS,QAAQ,GAAG,GAAG,EAAE;QAC7B,KAAK,EAAE,WAAW;KACrB,CAAC;IAEF,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAEvD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAEjC,MAAM,IAAI,GAAG,2BAAa,EAAE,CAAC;QAC7B,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;KACnC;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,uDAAuD,EAAE,CAAC,CAAC,EAAE;IAC9D,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;QAClC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QACjC,CAAC,CAAC,MAAM,CAAC,2BAAa,CAAC,CAAC;KAC3B;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,2DAA2D,EAAE,CAAC,CAAC,EAAE;IAElE,MAAM,OAAO,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;IAEjC,MAAM,KAAK,GAAG;QACV,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;QAClB,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE,aAAa,OAAO,EAAE;KAC7C,CAAC;IAEF,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAEvD,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC;QAErC,MAAM,IAAI,GAAG,4BAAc,EAAE,CAAC;QAC9B,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;KACnC;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,wDAAwD,EAAE,CAAC,CAAC,EAAE;IAC/D,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;QAClC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC;QACrC,CAAC,CAAC,MAAM,CAAC,4BAAc,CAAC,CAAC;KAC5B;AACL,CAAC,CAAC,CAAC"}
|
||||
58
src/finalize-db.test.ts
Normal file
58
src/finalize-db.test.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import test from "ava";
|
||||
import * as os from "os";
|
||||
|
||||
import {
|
||||
getMemoryFlag,
|
||||
getThreadsFlag
|
||||
} from "./finalize-db";
|
||||
|
||||
test('getMemoryFlag() should return the correct --ram flag', t => {
|
||||
|
||||
const totalMem = os.totalmem() / (1024 * 1024);
|
||||
|
||||
const tests = {
|
||||
"": `--ram=${totalMem - 256}`,
|
||||
"512": "--ram=512",
|
||||
};
|
||||
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
|
||||
process.env['INPUT_RAM'] = input;
|
||||
|
||||
const flag = getMemoryFlag();
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
|
||||
test('getMemoryFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
process.env['INPUT_RAM'] = input;
|
||||
t.throws(getMemoryFlag);
|
||||
}
|
||||
});
|
||||
|
||||
test('getThreadsFlag() should return the correct --threads flag', t => {
|
||||
|
||||
const numCpus = os.cpus().length;
|
||||
|
||||
const tests = {
|
||||
"0": "--threads=0",
|
||||
"1": "--threads=1",
|
||||
[`${numCpus + 1}`]: `--threads=${numCpus}`
|
||||
};
|
||||
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
|
||||
const flag = getThreadsFlag();
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
|
||||
test('getThreadsFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
t.throws(getThreadsFlag);
|
||||
}
|
||||
});
|
||||
|
|
@ -20,7 +20,7 @@ import * as util from './util';
|
|||
*
|
||||
* Format is a map from language to an array of path suffixes of .ql files.
|
||||
*/
|
||||
const DISABLED_BUILTIN_QUERIES: {[language: string]: string[]} = {
|
||||
const DISABLED_BUILTIN_QUERIES: { [language: string]: string[]; } = {
|
||||
'csharp': [
|
||||
'ql/src/Security Features/CWE-937/VulnerablePackage.ql',
|
||||
'ql/src/Security Features/CWE-451/MissingXFrameOptions.ql',
|
||||
|
|
@ -32,7 +32,7 @@ function queryIsDisabled(language, query): boolean {
|
|||
.some(disabledQuery => query.endsWith(disabledQuery));
|
||||
}
|
||||
|
||||
function getMemoryFlag(): string {
|
||||
export function getMemoryFlag(): string {
|
||||
let memoryToUseMegaBytes: number;
|
||||
const memoryToUseString = core.getInput("ram");
|
||||
if (memoryToUseString) {
|
||||
|
|
@ -49,6 +49,22 @@ function getMemoryFlag(): string {
|
|||
return "--ram=" + Math.floor(memoryToUseMegaBytes);
|
||||
}
|
||||
|
||||
export function getThreadsFlag(): string {
|
||||
let numThreads = 1;
|
||||
const numThreadsString = core.getInput("threads");
|
||||
if (numThreadsString) {
|
||||
numThreads = Number(numThreadsString);
|
||||
if (Number.isNaN(numThreads) || numThreads < 0) {
|
||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||
}
|
||||
const maxThreads = os.cpus().length;
|
||||
if (numThreads > maxThreads) {
|
||||
numThreads = maxThreads;
|
||||
}
|
||||
}
|
||||
return `--threads=${numThreads}`;
|
||||
}
|
||||
|
||||
async function createdDBForScannedLanguages(codeqlCmd: string, databaseFolder: string) {
|
||||
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
|
||||
if (scannedLanguages) {
|
||||
|
|
@ -93,14 +109,14 @@ async function finalizeDatabaseCreation(codeqlCmd: string, databaseFolder: strin
|
|||
interface ResolveQueriesOutput {
|
||||
byLanguage: {
|
||||
[language: string]: {
|
||||
[queryPath: string]: {}
|
||||
}
|
||||
[queryPath: string]: {};
|
||||
};
|
||||
};
|
||||
noDeclaredLanguage: {
|
||||
[queryPath: string]: {}
|
||||
[queryPath: string]: {};
|
||||
};
|
||||
multipleDeclaredLanguages: {
|
||||
[queryPath: string]: {}
|
||||
[queryPath: string]: {};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -116,11 +132,11 @@ async function runResolveQueries(codeqlCmd: string, queries: string[]): Promise<
|
|||
|
||||
await exec.exec(
|
||||
codeqlCmd, [
|
||||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
],
|
||||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
],
|
||||
options);
|
||||
|
||||
return JSON.parse(output);
|
||||
|
|
@ -201,6 +217,7 @@ async function runQueries(codeqlCmd: string, databaseFolder: string, sarifFolder
|
|||
'database',
|
||||
'analyze',
|
||||
getMemoryFlag(),
|
||||
getThreadsFlag(),
|
||||
path.join(databaseFolder, database),
|
||||
'--format=sarif-latest',
|
||||
'--output=' + sarifFile,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue