Skip to content

Commit 9eeab46

Browse files
committed
Add e2e test
1 parent e0fedcf commit 9eeab46

3 files changed

Lines changed: 161 additions & 0 deletions

File tree

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

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Diagnostic export without database"
2+
description: "Tests that temporary diagnostics are correctly included in the failed SARIF."
3+
versions:
4+
# Overriden by the FF below.
5+
- linked
6+
installNode: true
7+
steps:
8+
# We deliberately need to make this step fail before the database is initialised, but after
9+
# some diagnostic has been produced. The simplest way to do that right now is to force the
10+
# use of a nightly release and then fail because we are attempting to analyse Swift on
11+
# a non-macOS runner.
12+
- name: Initialise failing analysis
13+
id: init
14+
uses: ./../action/init
15+
continue-on-error: true
16+
env:
17+
CODEQL_ACTION_FORCE_NIGHTLY: true
18+
with:
19+
languages: swift
20+
tools: ${{ steps.prepare-test.outputs.tools-url }}
21+
22+
- name: Check diagnostics appear on disk
23+
env:
24+
SARIF_PATH: "${{ runner.temp }}/codeql-action-temp-diagnostics/"
25+
run: |
26+
cd ../action
27+
npx tsx ./pr-checks/diagnostics-without-db.ts
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
4+
import * as core from "@actions/core";
5+
6+
import type * as diagnostics from "../src/diagnostics";
7+
8+
const DIAGNOSTIC_ID = "codeql-action/forced-nightly-cli";
9+
const sarifDirectory = process.env["SARIF_PATH"];
10+
11+
if (sarifDirectory === undefined) {
12+
throw new Error("SARIF_PATH is undefined.");
13+
}
14+
15+
const paths = fs
16+
.readdirSync(sarifDirectory, {
17+
recursive: true,
18+
encoding: "utf-8",
19+
})
20+
.filter((p) => p.endsWith(".json"));
21+
22+
core.info(`Found ${paths.length} paths in '${sarifDirectory}'.`);
23+
core.info(`Searching for a diagnostic with id '${DIAGNOSTIC_ID}'...`);
24+
25+
let found = false;
26+
for (const diagnosticPath of paths) {
27+
if (path.extname(diagnosticPath) !== ".json") {
28+
core.info(`Skipping ${diagnosticPath}.`);
29+
continue;
30+
}
31+
core.info(`Found ${diagnosticPath}.`);
32+
33+
const contents = JSON.parse(
34+
fs.readFileSync(path.resolve(sarifDirectory, diagnosticPath), "utf-8"),
35+
) as diagnostics.DiagnosticMessage;
36+
37+
if (contents.source.id === DIAGNOSTIC_ID) {
38+
core.info(
39+
`Found '${DIAGNOSTIC_ID}' in '${diagnosticPath}'. Skipping remaining files.`,
40+
);
41+
found = true;
42+
break;
43+
}
44+
}
45+
46+
if (!found) {
47+
throw new Error(`Didn't find '${DIAGNOSTIC_ID}' diagnostic.`);
48+
}

0 commit comments

Comments
 (0)