Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6145d06

Browse files
committedFeb 8, 2024
Treat status reports as non-critical
Change `sendStatusReport` to `void`
1 parent cf7e9f2 commit 6145d06

29 files changed

+151
-140
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
66

77
## [UNRELEASED]
88

9-
No user facing changes.
9+
- The upload-sarif action should not fail if it can't write to the telemetry api endpoint [#2121](https://github.com/github/codeql-action/pull/2121)
1010

1111
## 3.24.0 - 02 Feb 2024
1212

‎lib/analyze-action-env.test.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/analyze-action-env.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/analyze-action-input.test.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/analyze-action-input.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/analyze-action.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/analyze-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/autobuild-action.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/autobuild-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/init-action.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/init-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/resolve-environment-action.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/resolve-environment-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/status-report.js

+14-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/status-report.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/upload-lib.js

+28-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/upload-lib.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/upload-sarif-action.js

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/upload-sarif-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeql",
3-
"version": "3.24.1",
3+
"version": "3.25.0",
44
"private": true,
55
"description": "CodeQL action",
66
"scripts": {

‎src/analyze-action-env.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test("analyze action with RAM & threads from environment variables", async (t) =
3030
sinon
3131
.stub(statusReport, "createStatusReportBase")
3232
.resolves({} as statusReport.StatusReportBase);
33-
sinon.stub(statusReport, "sendStatusReport").resolves(true);
33+
sinon.stub(statusReport, "sendStatusReport").resolves();
3434
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
3535

3636
const gitHubVersion: util.GitHubVersion = {

‎src/analyze-action-input.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test("analyze action with RAM & threads from action inputs", async (t) => {
3030
sinon
3131
.stub(statusReport, "createStatusReportBase")
3232
.resolves({} as statusReport.StatusReportBase);
33-
sinon.stub(statusReport, "sendStatusReport").resolves(true);
33+
sinon.stub(statusReport, "sendStatusReport").resolves();
3434
const gitHubVersion: util.GitHubVersion = {
3535
type: util.GitHubVariant.DOTCOM,
3636
};

‎src/analyze-action.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,15 @@ async function run() {
182182

183183
const logger = getActionsLogger();
184184
try {
185-
if (
186-
!(await statusReport.sendStatusReport(
187-
await createStatusReportBase(
188-
"finish",
189-
"starting",
190-
startedAt,
191-
await util.checkDiskUsage(logger),
192-
),
193-
))
194-
) {
195-
return;
196-
}
185+
await statusReport.sendStatusReport(
186+
await createStatusReportBase(
187+
"finish",
188+
"starting",
189+
startedAt,
190+
await util.checkDiskUsage(logger),
191+
),
192+
);
193+
197194
config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
198195
if (config === undefined) {
199196
throw new Error(

‎src/autobuild-action.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,14 @@ async function run() {
6363
let currentLanguage: Language | undefined = undefined;
6464
let languages: Language[] | undefined = undefined;
6565
try {
66-
if (
67-
!(await sendStatusReport(
68-
await createStatusReportBase(
69-
"autobuild",
70-
"starting",
71-
startedAt,
72-
await checkDiskUsage(logger),
73-
),
74-
))
75-
) {
76-
return;
77-
}
66+
await sendStatusReport(
67+
await createStatusReportBase(
68+
"autobuild",
69+
"starting",
70+
startedAt,
71+
await checkDiskUsage(logger),
72+
),
73+
);
7874

7975
const gitHubVersion = await getGitHubVersion();
8076
checkGitHubVersionInRange(gitHubVersion, logger);

‎src/init-action.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,14 @@ async function run() {
229229
core.exportVariable(EnvVar.JOB_RUN_UUID, uuidV4());
230230

231231
try {
232-
if (
233-
!(await sendStatusReport(
234-
await createStatusReportBase(
235-
"init",
236-
"starting",
237-
startedAt,
238-
await checkDiskUsage(logger),
239-
),
240-
))
241-
) {
242-
return;
243-
}
232+
await sendStatusReport(
233+
await createStatusReportBase(
234+
"init",
235+
"starting",
236+
startedAt,
237+
await checkDiskUsage(logger),
238+
),
239+
);
244240

245241
const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
246242
gitHubVersion.type,

‎src/resolve-environment-action.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ async function run() {
3232
const logger = getActionsLogger();
3333

3434
try {
35-
if (
36-
!(await sendStatusReport(
37-
await createStatusReportBase(
38-
ACTION_NAME,
39-
"starting",
40-
startedAt,
41-
await checkDiskUsage(logger),
42-
),
43-
))
44-
) {
45-
return;
46-
}
35+
await sendStatusReport(
36+
await createStatusReportBase(
37+
ACTION_NAME,
38+
"starting",
39+
startedAt,
40+
await checkDiskUsage(logger),
41+
),
42+
);
4743

4844
const gitHubVersion = await getGitHubVersion();
4945
checkGitHubVersionInRange(gitHubVersion, logger);

‎src/status-report.ts

+15-17
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,6 @@ export async function createStatusReportBase(
282282
return statusReport;
283283
}
284284

285-
const GENERIC_403_MSG =
286-
"The repo on which this action is running is not opted-in to CodeQL code scanning.";
287-
const GENERIC_404_MSG =
288-
"Not authorized to use the CodeQL code scanning feature on this repo.";
289285
const OUT_OF_DATE_MSG =
290286
"CodeQL Action is out-of-date. Please upgrade to the latest version of codeql-action.";
291287
const INCOMPATIBLE_MSG =
@@ -298,19 +294,24 @@ const INCOMPATIBLE_MSG =
298294
* as failed if the status report failed. This is only expected to be used
299295
* when sending a 'starting' report.
300296
*
301-
* Returns whether sending the status report was successful of not.
297+
* This API it calls is private and it is not critical that it succeed:
298+
* https://github.com/github/codeql/issues/15462#issuecomment-1919186317
299+
*
300+
* Do not worry about whether a report is/isn't submitted.
301+
* Just go about your business.
302+
* The side effects of this call are not relevant to your program.
302303
*/
303304
export async function sendStatusReport<S extends StatusReportBase>(
304305
statusReport: S,
305-
): Promise<boolean> {
306+
): Promise<void> {
306307
setJobStatusIfUnsuccessful(statusReport.status);
307308

308309
const statusReportJSON = JSON.stringify(statusReport);
309310
core.debug(`Sending status report: ${statusReportJSON}`);
310311
// If in test mode we don't want to upload the results
311312
if (isInTestMode()) {
312313
core.debug("In test mode. Status reports are not uploaded.");
313-
return true;
314+
return;
314315
}
315316

316317
const nwo = getRequiredEnvParam("GITHUB_REPOSITORY");
@@ -326,8 +327,6 @@ export async function sendStatusReport<S extends StatusReportBase>(
326327
data: statusReportJSON,
327328
},
328329
);
329-
330-
return true;
331330
} catch (e) {
332331
console.log(e);
333332
if (isHTTPError(e)) {
@@ -337,19 +336,19 @@ export async function sendStatusReport<S extends StatusReportBase>(
337336
getWorkflowEventName() === "push" &&
338337
process.env["GITHUB_ACTOR"] === "dependabot[bot]"
339338
) {
340-
core.setFailed(
339+
core.warning(
341340
'Workflows triggered by Dependabot on the "push" event run with read-only access. ' +
342341
"Uploading Code Scanning results requires write access. " +
343342
'To use Code Scanning with Dependabot, please ensure you are using the "pull_request" event for this workflow and avoid triggering on the "push" event for Dependabot branches. ' +
344343
"See https://docs.github.com/en/code-security/secure-coding/configuring-code-scanning#scanning-on-push for more information on how to configure these events.",
345344
);
346345
} else {
347-
core.setFailed(e.message || GENERIC_403_MSG);
346+
core.warning(e.message);
348347
}
349-
return false;
348+
return;
350349
case 404:
351-
core.setFailed(GENERIC_404_MSG);
352-
return false;
350+
core.warning(e.message);
351+
return;
353352
case 422:
354353
// schema incompatibility when reporting status
355354
// this means that this action version is no longer compatible with the API
@@ -359,15 +358,14 @@ export async function sendStatusReport<S extends StatusReportBase>(
359358
} else {
360359
core.debug(OUT_OF_DATE_MSG);
361360
}
362-
return true;
361+
return;
363362
}
364363
}
365364

366365
// something else has gone wrong and the request/response will be logged by octokit
367366
// it's possible this is a transient error and we should continue scanning
368-
core.error(
367+
core.warning(
369368
"An unexpected error occurred when sending code scanning status report.",
370369
);
371-
return true;
372370
}
373371
}

‎src/upload-lib.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { parseRepositoryNwo, RepositoryNwo } from "./repository";
1616
import * as util from "./util";
1717
import { SarifFile, UserError, wrapError } from "./util";
1818

19+
const GENERIC_403_MSG =
20+
"The repo on which this action is running is not opted-in to CodeQL code scanning.";
21+
const GENERIC_404_MSG =
22+
"Not authorized to use the CodeQL code scanning feature on this repo.";
23+
1924
// Takes a list of paths to sarif files and combines them together,
2025
// returning the contents of the combined sarif file.
2126
function combineSarifFiles(sarifFiles: string[]): SarifFile {
@@ -107,19 +112,35 @@ async function uploadPayload(
107112

108113
const client = api.getApiClient();
109114

110-
const response = await client.request(
111-
"PUT /repos/:owner/:repo/code-scanning/analysis",
112-
{
113-
owner: repositoryNwo.owner,
114-
repo: repositoryNwo.repo,
115-
data: payload,
116-
},
117-
);
118-
119-
logger.debug(`response status: ${response.status}`);
120-
logger.info("Successfully uploaded results");
115+
try {
116+
const response = await client.request(
117+
"PUT /repos/:owner/:repo/code-scanning/analysis",
118+
{
119+
owner: repositoryNwo.owner,
120+
repo: repositoryNwo.repo,
121+
data: payload,
122+
},
123+
);
121124

122-
return response.data.id;
125+
logger.debug(`response status: ${response.status}`);
126+
logger.info("Successfully uploaded results");
127+
return response.data.id;
128+
} catch (e) {
129+
if (util.isHTTPError(e)) {
130+
switch (e.status) {
131+
case 403:
132+
core.warning(e.message || GENERIC_403_MSG);
133+
break;
134+
case 404:
135+
core.warning(e.message || GENERIC_404_MSG);
136+
break;
137+
default:
138+
core.warning(e.message);
139+
break;
140+
}
141+
}
142+
throw e;
143+
}
123144
}
124145

125146
export interface UploadStatusReport {

‎src/upload-sarif-action.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,14 @@ async function run() {
5050
const gitHubVersion = await getGitHubVersion();
5151
checkActionVersion(getActionVersion(), gitHubVersion);
5252

53-
if (
54-
!(await sendStatusReport(
55-
await createStatusReportBase(
56-
"upload-sarif",
57-
"starting",
58-
startedAt,
59-
await checkDiskUsage(),
60-
),
61-
))
62-
) {
63-
return;
64-
}
53+
await sendStatusReport(
54+
await createStatusReportBase(
55+
"upload-sarif",
56+
"starting",
57+
startedAt,
58+
await checkDiskUsage(),
59+
),
60+
);
6561

6662
try {
6763
const uploadResult = await upload_lib.uploadFromActions(

0 commit comments

Comments
 (0)
Please sign in to comment.