mirror of
https://github.com/github/codeql-action.git
synced 2025-12-08 16:58:06 +08:00
Compare commits
2 Commits
v3.26.1
...
always-rep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cd2eff354 | ||
|
|
cce113b7fc |
63
lib/config-utils.js
generated
63
lib/config-utils.js
generated
@@ -71,41 +71,36 @@ function initConfig() {
|
|||||||
core.debug('No configuration file was provided');
|
core.debug('No configuration file was provided');
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
try {
|
const parsedYAML = yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
|
||||||
const parsedYAML = yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
|
if (parsedYAML.name && typeof parsedYAML.name === "string") {
|
||||||
if (parsedYAML.name && typeof parsedYAML.name === "string") {
|
config.name = parsedYAML.name;
|
||||||
config.name = parsedYAML.name;
|
|
||||||
}
|
|
||||||
if (parsedYAML['disable-default-queries'] && typeof parsedYAML['disable-default-queries'] === "boolean") {
|
|
||||||
config.disableDefaultQueries = parsedYAML['disable-default-queries'];
|
|
||||||
}
|
|
||||||
const queries = parsedYAML.queries;
|
|
||||||
if (queries && queries instanceof Array) {
|
|
||||||
queries.forEach(query => {
|
|
||||||
if (query.uses && typeof query.uses === "string") {
|
|
||||||
config.addQuery(query.uses);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const pathsIgnore = parsedYAML['paths-ignore'];
|
|
||||||
if (pathsIgnore && pathsIgnore instanceof Array) {
|
|
||||||
pathsIgnore.forEach(path => {
|
|
||||||
if (typeof path === "string") {
|
|
||||||
config.pathsIgnore.push(path);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const paths = parsedYAML.paths;
|
|
||||||
if (paths && paths instanceof Array) {
|
|
||||||
paths.forEach(path => {
|
|
||||||
if (typeof path === "string") {
|
|
||||||
config.paths.push(path);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
if (parsedYAML['disable-default-queries'] && typeof parsedYAML['disable-default-queries'] === "boolean") {
|
||||||
core.setFailed(err);
|
config.disableDefaultQueries = parsedYAML['disable-default-queries'];
|
||||||
|
}
|
||||||
|
const queries = parsedYAML.queries;
|
||||||
|
if (queries && queries instanceof Array) {
|
||||||
|
queries.forEach(query => {
|
||||||
|
if (query.uses && typeof query.uses === "string") {
|
||||||
|
config.addQuery(query.uses);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const pathsIgnore = parsedYAML['paths-ignore'];
|
||||||
|
if (pathsIgnore && pathsIgnore instanceof Array) {
|
||||||
|
pathsIgnore.forEach(path => {
|
||||||
|
if (typeof path === "string") {
|
||||||
|
config.pathsIgnore.push(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const paths = parsedYAML.paths;
|
||||||
|
if (paths && paths instanceof Array) {
|
||||||
|
paths.forEach(path => {
|
||||||
|
if (typeof path === "string") {
|
||||||
|
config.paths.push(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|||||||
2
lib/finalize-db.js
generated
2
lib/finalize-db.js
generated
@@ -126,7 +126,7 @@ async function run() {
|
|||||||
await runQueries(codeqlCmd, databaseFolder, sarifFolder, config);
|
await runQueries(codeqlCmd, databaseFolder, sarifFolder, config);
|
||||||
if ('true' === core.getInput('upload')) {
|
if ('true' === core.getInput('upload')) {
|
||||||
if (!await upload_lib.upload(sarifFolder)) {
|
if (!await upload_lib.upload(sarifFolder)) {
|
||||||
await util.reportActionFailed('failed', 'upload');
|
await util.reportActionFailed('finish', 'upload');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
lib/setup-tracer.js
generated
2
lib/setup-tracer.js
generated
@@ -205,8 +205,8 @@ async function run() {
|
|||||||
await util.reportActionFailed('init', error.message, error.stack);
|
await util.reportActionFailed('init', error.message, error.stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.exportVariable(sharedEnv.CODEQL_ACTION_INIT_COMPLETED, 'true');
|
|
||||||
await util.reportActionSucceeded('init');
|
await util.reportActionSucceeded('init');
|
||||||
|
core.exportVariable(sharedEnv.CODEQL_ACTION_INIT_COMPLETED, 'true');
|
||||||
}
|
}
|
||||||
run().catch(e => {
|
run().catch(e => {
|
||||||
core.setFailed("init action failed: " + e);
|
core.setFailed("init action failed: " + e);
|
||||||
|
|||||||
89
lib/upload-lib.js
generated
89
lib/upload-lib.js
generated
@@ -125,55 +125,50 @@ exports.upload = upload;
|
|||||||
async function uploadFiles(sarifFiles) {
|
async function uploadFiles(sarifFiles) {
|
||||||
core.startGroup("Uploading results");
|
core.startGroup("Uploading results");
|
||||||
let succeeded = false;
|
let succeeded = false;
|
||||||
try {
|
// Check if an upload has happened before. If so then abort.
|
||||||
// Check if an upload has happened before. If so then abort.
|
// This is intended to catch when the finish and upload-sarif actions
|
||||||
// This is intended to catch when the finish and upload-sarif actions
|
// are used together, and then the upload-sarif action is invoked twice.
|
||||||
// are used together, and then the upload-sarif action is invoked twice.
|
const sentinelFile = await getSentinelFilePath();
|
||||||
const sentinelFile = await getSentinelFilePath();
|
if (fs.existsSync(sentinelFile)) {
|
||||||
if (fs.existsSync(sentinelFile)) {
|
core.info("Aborting as an upload has already happened from this job");
|
||||||
core.info("Aborting as an upload has already happened from this job");
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
|
||||||
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
|
||||||
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
|
|
||||||
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
|
|
||||||
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
|
|
||||||
core.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
|
|
||||||
let sarifPayload = combineSarifFiles(sarifFiles);
|
|
||||||
sarifPayload = fingerprints.addFingerprints(sarifPayload);
|
|
||||||
const zipped_sarif = zlib_1.default.gzipSync(sarifPayload).toString('base64');
|
|
||||||
let checkoutPath = core.getInput('checkout_path');
|
|
||||||
let checkoutURI = file_url_1.default(checkoutPath);
|
|
||||||
const workflowRunID = parseInt(workflowRunIDStr, 10);
|
|
||||||
if (Number.isNaN(workflowRunID)) {
|
|
||||||
core.setFailed('GITHUB_RUN_ID must define a non NaN workflow run ID');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let matrix = core.getInput('matrix');
|
|
||||||
if (matrix === "null" || matrix === "") {
|
|
||||||
matrix = undefined;
|
|
||||||
}
|
|
||||||
const toolNames = util.getToolNames(sarifPayload);
|
|
||||||
const payload = JSON.stringify({
|
|
||||||
"commit_oid": commitOid,
|
|
||||||
"ref": ref,
|
|
||||||
"analysis_name": analysisName,
|
|
||||||
"sarif": zipped_sarif,
|
|
||||||
"workflow_run_id": workflowRunID,
|
|
||||||
"checkout_uri": checkoutURI,
|
|
||||||
"environment": matrix,
|
|
||||||
"started_at": startedAt,
|
|
||||||
"tool_names": toolNames,
|
|
||||||
});
|
|
||||||
// Make the upload
|
|
||||||
succeeded = await uploadPayload(payload);
|
|
||||||
// Mark that we have made an upload
|
|
||||||
fs.writeFileSync(sentinelFile, '');
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
||||||
core.setFailed(error.message);
|
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
||||||
|
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
|
||||||
|
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
|
||||||
|
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
|
||||||
|
core.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
|
||||||
|
let sarifPayload = combineSarifFiles(sarifFiles);
|
||||||
|
sarifPayload = fingerprints.addFingerprints(sarifPayload);
|
||||||
|
const zipped_sarif = zlib_1.default.gzipSync(sarifPayload).toString('base64');
|
||||||
|
let checkoutPath = core.getInput('checkout_path');
|
||||||
|
let checkoutURI = file_url_1.default(checkoutPath);
|
||||||
|
const workflowRunID = parseInt(workflowRunIDStr, 10);
|
||||||
|
if (Number.isNaN(workflowRunID)) {
|
||||||
|
core.setFailed('GITHUB_RUN_ID must define a non NaN workflow run ID');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
let matrix = core.getInput('matrix');
|
||||||
|
if (matrix === "null" || matrix === "") {
|
||||||
|
matrix = undefined;
|
||||||
|
}
|
||||||
|
const toolNames = util.getToolNames(sarifPayload);
|
||||||
|
const payload = JSON.stringify({
|
||||||
|
"commit_oid": commitOid,
|
||||||
|
"ref": ref,
|
||||||
|
"analysis_name": analysisName,
|
||||||
|
"sarif": zipped_sarif,
|
||||||
|
"workflow_run_id": workflowRunID,
|
||||||
|
"checkout_uri": checkoutURI,
|
||||||
|
"environment": matrix,
|
||||||
|
"started_at": startedAt,
|
||||||
|
"tool_names": toolNames,
|
||||||
|
});
|
||||||
|
// Make the upload
|
||||||
|
succeeded = await uploadPayload(payload);
|
||||||
|
// Mark that we have made an upload
|
||||||
|
fs.writeFileSync(sentinelFile, '');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
return succeeded;
|
return succeeded;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,45 +75,41 @@ function initConfig(): Config {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const parsedYAML = yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
|
||||||
const parsedYAML = yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
|
|
||||||
|
|
||||||
if (parsedYAML.name && typeof parsedYAML.name === "string") {
|
if (parsedYAML.name && typeof parsedYAML.name === "string") {
|
||||||
config.name = parsedYAML.name;
|
config.name = parsedYAML.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedYAML['disable-default-queries'] && typeof parsedYAML['disable-default-queries'] === "boolean") {
|
if (parsedYAML['disable-default-queries'] && typeof parsedYAML['disable-default-queries'] === "boolean") {
|
||||||
config.disableDefaultQueries = parsedYAML['disable-default-queries'];
|
config.disableDefaultQueries = parsedYAML['disable-default-queries'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const queries = parsedYAML.queries;
|
const queries = parsedYAML.queries;
|
||||||
if (queries && queries instanceof Array) {
|
if (queries && queries instanceof Array) {
|
||||||
queries.forEach(query => {
|
queries.forEach(query => {
|
||||||
if (query.uses && typeof query.uses === "string") {
|
if (query.uses && typeof query.uses === "string") {
|
||||||
config.addQuery(query.uses);
|
config.addQuery(query.uses);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathsIgnore = parsedYAML['paths-ignore'];
|
const pathsIgnore = parsedYAML['paths-ignore'];
|
||||||
if (pathsIgnore && pathsIgnore instanceof Array) {
|
if (pathsIgnore && pathsIgnore instanceof Array) {
|
||||||
pathsIgnore.forEach(path => {
|
pathsIgnore.forEach(path => {
|
||||||
if (typeof path === "string") {
|
if (typeof path === "string") {
|
||||||
config.pathsIgnore.push(path);
|
config.pathsIgnore.push(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const paths = parsedYAML.paths;
|
const paths = parsedYAML.paths;
|
||||||
if (paths && paths instanceof Array) {
|
if (paths && paths instanceof Array) {
|
||||||
paths.forEach(path => {
|
paths.forEach(path => {
|
||||||
if (typeof path === "string") {
|
if (typeof path === "string") {
|
||||||
config.paths.push(path);
|
config.paths.push(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ async function run() {
|
|||||||
|
|
||||||
if ('true' === core.getInput('upload')) {
|
if ('true' === core.getInput('upload')) {
|
||||||
if (!await upload_lib.upload(sarifFolder)) {
|
if (!await upload_lib.upload(sarifFolder)) {
|
||||||
await util.reportActionFailed('failed', 'upload');
|
await util.reportActionFailed('finish', 'upload');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ async function run() {
|
|||||||
await util.reportActionFailed('init', error.message, error.stack);
|
await util.reportActionFailed('init', error.message, error.stack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.exportVariable(sharedEnv.CODEQL_ACTION_INIT_COMPLETED, 'true');
|
|
||||||
await util.reportActionSucceeded('init');
|
await util.reportActionSucceeded('init');
|
||||||
|
core.exportVariable(sharedEnv.CODEQL_ACTION_INIT_COMPLETED, 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(e => {
|
run().catch(e => {
|
||||||
|
|||||||
@@ -127,64 +127,61 @@ export async function upload(input: string): Promise<boolean> {
|
|||||||
async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
|
async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
|
||||||
core.startGroup("Uploading results");
|
core.startGroup("Uploading results");
|
||||||
let succeeded = false;
|
let succeeded = false;
|
||||||
try {
|
|
||||||
// Check if an upload has happened before. If so then abort.
|
|
||||||
// This is intended to catch when the finish and upload-sarif actions
|
|
||||||
// are used together, and then the upload-sarif action is invoked twice.
|
|
||||||
const sentinelFile = await getSentinelFilePath();
|
|
||||||
if (fs.existsSync(sentinelFile)) {
|
|
||||||
core.info("Aborting as an upload has already happened from this job");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
// Check if an upload has happened before. If so then abort.
|
||||||
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
// This is intended to catch when the finish and upload-sarif actions
|
||||||
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
|
// are used together, and then the upload-sarif action is invoked twice.
|
||||||
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
|
const sentinelFile = await getSentinelFilePath();
|
||||||
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
|
if (fs.existsSync(sentinelFile)) {
|
||||||
|
core.info("Aborting as an upload has already happened from this job");
|
||||||
core.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
|
return false;
|
||||||
let sarifPayload = combineSarifFiles(sarifFiles);
|
|
||||||
sarifPayload = fingerprints.addFingerprints(sarifPayload);
|
|
||||||
|
|
||||||
const zipped_sarif = zlib.gzipSync(sarifPayload).toString('base64');
|
|
||||||
let checkoutPath = core.getInput('checkout_path');
|
|
||||||
let checkoutURI = fileUrl(checkoutPath);
|
|
||||||
const workflowRunID = parseInt(workflowRunIDStr, 10);
|
|
||||||
|
|
||||||
if (Number.isNaN(workflowRunID)) {
|
|
||||||
core.setFailed('GITHUB_RUN_ID must define a non NaN workflow run ID');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let matrix: string | undefined = core.getInput('matrix');
|
|
||||||
if (matrix === "null" || matrix === "") {
|
|
||||||
matrix = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const toolNames = util.getToolNames(sarifPayload);
|
|
||||||
|
|
||||||
const payload = JSON.stringify({
|
|
||||||
"commit_oid": commitOid,
|
|
||||||
"ref": ref,
|
|
||||||
"analysis_name": analysisName,
|
|
||||||
"sarif": zipped_sarif,
|
|
||||||
"workflow_run_id": workflowRunID,
|
|
||||||
"checkout_uri": checkoutURI,
|
|
||||||
"environment": matrix,
|
|
||||||
"started_at": startedAt,
|
|
||||||
"tool_names": toolNames,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Make the upload
|
|
||||||
succeeded = await uploadPayload(payload);
|
|
||||||
|
|
||||||
// Mark that we have made an upload
|
|
||||||
fs.writeFileSync(sentinelFile, '');
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed(error.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
|
||||||
|
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
|
||||||
|
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
|
||||||
|
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
|
||||||
|
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
|
||||||
|
|
||||||
|
core.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
|
||||||
|
let sarifPayload = combineSarifFiles(sarifFiles);
|
||||||
|
sarifPayload = fingerprints.addFingerprints(sarifPayload);
|
||||||
|
|
||||||
|
const zipped_sarif = zlib.gzipSync(sarifPayload).toString('base64');
|
||||||
|
let checkoutPath = core.getInput('checkout_path');
|
||||||
|
let checkoutURI = fileUrl(checkoutPath);
|
||||||
|
const workflowRunID = parseInt(workflowRunIDStr, 10);
|
||||||
|
|
||||||
|
if (Number.isNaN(workflowRunID)) {
|
||||||
|
core.setFailed('GITHUB_RUN_ID must define a non NaN workflow run ID');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let matrix: string | undefined = core.getInput('matrix');
|
||||||
|
if (matrix === "null" || matrix === "") {
|
||||||
|
matrix = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const toolNames = util.getToolNames(sarifPayload);
|
||||||
|
|
||||||
|
const payload = JSON.stringify({
|
||||||
|
"commit_oid": commitOid,
|
||||||
|
"ref": ref,
|
||||||
|
"analysis_name": analysisName,
|
||||||
|
"sarif": zipped_sarif,
|
||||||
|
"workflow_run_id": workflowRunID,
|
||||||
|
"checkout_uri": checkoutURI,
|
||||||
|
"environment": matrix,
|
||||||
|
"started_at": startedAt,
|
||||||
|
"tool_names": toolNames,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Make the upload
|
||||||
|
succeeded = await uploadPayload(payload);
|
||||||
|
|
||||||
|
// Mark that we have made an upload
|
||||||
|
fs.writeFileSync(sentinelFile, '');
|
||||||
|
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
|
|
||||||
return succeeded;
|
return succeeded;
|
||||||
|
|||||||
Reference in New Issue
Block a user