Skip to content

Commit 12b2055

Browse files
committed
Use check-diagnostics.ts in diagnostics-without-db.yml
1 parent 0a16024 commit 12b2055

3 files changed

Lines changed: 48 additions & 13 deletions

File tree

‎.github/workflows/__diagnostics-without-db.yml‎

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

‎pr-checks/check-diagnostics.ts‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,32 @@ import * as core from "@actions/core";
44

55
import * as sarif from "../src/sarif";
66

7-
function checkStatusPageNotification(n) {
8-
const expectedMessage = "Plaintext message";
9-
if (n.message.text !== expectedMessage) {
10-
core.setFailed(
11-
`Expected the status page diagnostic to have the message '${expectedMessage}', but found '${n.message.text}'.`,
12-
);
7+
const DIAGNOSTIC_ID =
8+
process.env["DIAGNOSTIC_ID"] ?? "lang/diagnostics/example";
9+
const DIAGNOSTIC_NAME = process.env["DIAGNOSTIC_NAME"] ?? "Diagnostic name";
10+
const EXPECTED_MESSAGE = process.env["EXPECTED_MESSAGE"] ?? "Plaintext message";
11+
const EXPECTED_LOCATIONS = Number.parseInt(
12+
process.env["EXPECTED_LOCATIONS"] ?? "1",
13+
);
14+
15+
function checkStatusPageNotification(n: sarif.Notification) {
16+
const expectedMessage = EXPECTED_MESSAGE.trim();
17+
if (!n.message.text?.includes(expectedMessage)) {
18+
if (n.message.text !== undefined) {
19+
core.setFailed(
20+
`Expected the status page diagnostic to contain the message '${expectedMessage}', but found '${n.message.text.replaceAll("\n", "\\n")}'.`,
21+
);
22+
} else {
23+
core.setFailed(
24+
`Expected the status page diagnostic to contain the message '${expectedMessage}', but found nothing.`,
25+
);
26+
}
1327
}
14-
if (n.locations.length !== 1) {
28+
29+
const locationCount = n.locations?.length ?? 0;
30+
if (locationCount !== EXPECTED_LOCATIONS) {
1531
core.setFailed(
16-
`Expected the status page diagnostic to have exactly 1 location, but found ${n.locations.length}.`,
32+
`Expected the status page diagnostic to have exactly ${EXPECTED_LOCATIONS} location(s), but found ${locationCount}.`,
1733
);
1834
}
1935
}
@@ -40,8 +56,7 @@ if (toolExecutionNotifications === undefined) {
4056

4157
const statusPageNotifications = toolExecutionNotifications.filter(
4258
(n) =>
43-
n.descriptor?.id === "lang/diagnostics/example" &&
44-
n.properties?.visibility?.statusPage,
59+
n.descriptor?.id === DIAGNOSTIC_ID && n.properties?.visibility?.statusPage,
4560
);
4661
if (statusPageNotifications.length !== 1) {
4762
core.setFailed(
@@ -61,9 +76,9 @@ if (notifications === undefined) {
6176

6277
const diagnosticNotification = notifications.filter(
6378
(n) =>
64-
n.id === "lang/diagnostics/example" &&
65-
n.name === "lang/diagnostics/example" &&
66-
n.fullDescription?.text === "Diagnostic name",
79+
n.id === DIAGNOSTIC_ID &&
80+
n.name === DIAGNOSTIC_ID &&
81+
n.fullDescription?.text === DIAGNOSTIC_NAME,
6782
);
6883
if (diagnosticNotification.length !== 1) {
6984
core.setFailed(

‎pr-checks/checks/diagnostics-without-db.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ validationJobs:
5555

5656
- name: List artifact contents
5757
run: ls -laR ./sarif
58+
59+
- name: Check diagnostics appear in SARIF
60+
env:
61+
SARIF_PATH: "./sarif/codeql-failed-run.sarif"
62+
DIAGNOSTIC_ID: "codeql-action/forced-nightly-cli"
63+
DIAGNOSTIC_NAME: "A nightly release of CodeQL was used"
64+
EXPECTED_LOCATIONS: "0"
65+
EXPECTED_MESSAGE: |
66+
GitHub configured this analysis to use a nightly release of CodeQL to allow you to preview changes from an upcoming release.
67+
run: npx tsx ./pr-checks/check-diagnostics.ts

0 commit comments

Comments
 (0)