mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 09:14:58 +00:00
report exceptions during upload
This commit is contained in:
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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