Skip to content

Commit 984552a

Browse files
author
Max Veytsman
authored
Merge branch 'master' into autobuild_errors
2 parents 1fe0932 + d46c1c7 commit 984552a

File tree

6 files changed

+62
-30
lines changed

6 files changed

+62
-30
lines changed

lib/finalize-db.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif.js

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/finalize-db.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ async function run() {
150150
await runQueries(codeqlCmd, databaseFolder, sarifFolder, config);
151151

152152
if ('true' === core.getInput('upload')) {
153-
await upload_lib.upload(sarifFolder);
153+
if (!await upload_lib.upload(sarifFolder)) {
154+
await util.reportActionFailed('failed', 'upload');
155+
return;
156+
}
154157
}
155158

156159
} catch (error) {

src/upload-lib.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function combineSarifFiles(sarifFiles: string[]): string {
4949

5050
// Upload the given payload.
5151
// If the request fails then this will retry a small number of times.
52-
async function uploadPayload(payload) {
52+
async function uploadPayload(payload): Promise<boolean> {
5353
core.info('Uploading results');
5454

5555
const githubToken = core.getInput('token');
@@ -71,15 +71,15 @@ async function uploadPayload(payload) {
7171
const statusCode = res.message.statusCode;
7272
if (statusCode === 202) {
7373
core.info("Successfully uploaded results");
74-
return;
74+
return true;
7575
}
7676

7777
const requestID = res.message.headers["x-github-request-id"];
7878

7979
// On any other status code that's not 5xx mark the upload as failed
8080
if (!statusCode || statusCode < 500 || statusCode >= 600) {
8181
core.setFailed('Upload failed (' + requestID + '): (' + statusCode + ') ' + await res.readBody());
82-
return;
82+
return false;
8383
}
8484

8585
// On a 5xx status code we may retry the request
@@ -97,35 +97,44 @@ async function uploadPayload(payload) {
9797
// and not an error that the user has caused or can fix.
9898
// We avoid marking the job as failed to avoid breaking CI workflows.
9999
core.error('Upload failed (' + requestID + '): (' + statusCode + ') ' + await res.readBody());
100-
return;
100+
return false;
101101
}
102102
}
103+
104+
return false;
103105
}
104106

105107
// Uploads a single sarif file or a directory of sarif files
106108
// depending on what the path happens to refer to.
107-
export async function upload(input: string) {
109+
// Returns true iff the upload occurred and succeeded
110+
export async function upload(input: string): Promise<boolean> {
108111
if (fs.lstatSync(input).isDirectory()) {
109112
const sarifFiles = fs.readdirSync(input)
110113
.filter(f => f.endsWith(".sarif"))
111114
.map(f => path.resolve(input, f));
112-
await uploadFiles(sarifFiles);
115+
if (sarifFiles.length === 0) {
116+
core.setFailed("No SARIF files found to upload in \"" + input + "\".");
117+
return false;
118+
}
119+
return await uploadFiles(sarifFiles);
113120
} else {
114-
await uploadFiles([input]);
121+
return await uploadFiles([input]);
115122
}
116123
}
117124

118125
// Uploads the given set of sarif files.
119-
async function uploadFiles(sarifFiles: string[]) {
126+
// Returns true iff the upload occurred and succeeded
127+
async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
120128
core.startGroup("Uploading results");
129+
let succeeded = false;
121130
try {
122131
// Check if an upload has happened before. If so then abort.
123132
// This is intended to catch when the finish and upload-sarif actions
124133
// are used together, and then the upload-sarif action is invoked twice.
125134
const sentinelFile = await getSentinelFilePath();
126135
if (fs.existsSync(sentinelFile)) {
127136
core.info("Aborting as an upload has already happened from this job");
128-
return;
137+
return false;
129138
}
130139

131140
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
@@ -134,7 +143,7 @@ async function uploadFiles(sarifFiles: string[]) {
134143
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
135144
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
136145

137-
core.debug("Uploading sarif files: " + JSON.stringify(sarifFiles));
146+
core.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
138147
let sarifPayload = combineSarifFiles(sarifFiles);
139148
sarifPayload = fingerprints.addFingerprints(sarifPayload);
140149

@@ -145,7 +154,7 @@ async function uploadFiles(sarifFiles: string[]) {
145154

146155
if (Number.isNaN(workflowRunID)) {
147156
core.setFailed('GITHUB_RUN_ID must define a non NaN workflow run ID');
148-
return;
157+
return false;
149158
}
150159

151160
let matrix: string | undefined = core.getInput('matrix');
@@ -168,7 +177,7 @@ async function uploadFiles(sarifFiles: string[]) {
168177
});
169178

170179
// Make the upload
171-
await uploadPayload(payload);
180+
succeeded = await uploadPayload(payload);
172181

173182
// Mark that we have made an upload
174183
fs.writeFileSync(sentinelFile, '');
@@ -177,4 +186,6 @@ async function uploadFiles(sarifFiles: string[]) {
177186
core.setFailed(error.message);
178187
}
179188
core.endGroup();
189+
190+
return succeeded;
180191
}

src/upload-sarif.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ async function run() {
99
}
1010

1111
try {
12-
await upload_lib.upload(core.getInput('sarif_file'));
12+
if (await upload_lib.upload(core.getInput('sarif_file'))) {
13+
await util.reportActionSucceeded('upload-sarif');
14+
} else {
15+
await util.reportActionFailed('upload-sarif', 'upload');
16+
}
1317
} catch (error) {
1418
core.setFailed(error.message);
1519
await util.reportActionFailed('upload-sarif', error.message, error.stack);
1620
return;
1721
}
18-
19-
await util.reportActionSucceeded('upload-sarif');
2022
}
2123

2224
run().catch(e => {
23-
core.setFailed("upload-sarif action failed: " + e);
25+
core.setFailed("codeql/upload-sarif action failed: " + e);
2426
console.log(e);
2527
});

0 commit comments

Comments
 (0)