Skip to content

Commit 354d3a2

Browse files
authored
Merge pull request #4262 from github/mbg/cherry-picks/macos-deprecation
Minor improvements to prepare for #4221
2 parents 166cc10 + 2dc8ba8 commit 354d3a2

13 files changed

Lines changed: 357 additions & 160 deletions

‎lib/entry-points.js‎

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

‎package-lock.json‎

Lines changed: 1 addition & 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: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "fs";
2+
import path from "path";
23

34
import * as core from "@actions/core";
5+
import { globSync } from "glob";
46

57
import * as sarif from "../src/sarif";
68

@@ -34,59 +36,83 @@ function checkStatusPageNotification(n: sarif.Notification) {
3436
}
3537
}
3638

37-
const sarifPath = process.env["SARIF_PATH"];
39+
function checkSarif(sarifFile: string) {
40+
core.info(`Checking SARIF file at '${sarifFile}'`);
3841

39-
if (sarifPath === undefined) {
40-
throw new Error("The path to a SARIF file must be set in 'SARIF_PATH'.");
41-
}
42+
const log = JSON.parse(fs.readFileSync(sarifFile, "utf8")) as sarif.Log;
43+
const run = log.runs[0];
4244

43-
const log = JSON.parse(fs.readFileSync(sarifPath, "utf8")) as sarif.Log;
44-
const run = log.runs[0];
45+
if (run.invocations === undefined) {
46+
throw new Error("run.invocations is undefined");
47+
}
4548

46-
if (run.invocations === undefined) {
47-
throw new Error("run.invocations is undefined");
48-
}
49+
const toolExecutionNotifications =
50+
run.invocations[0].toolExecutionNotifications;
4951

50-
const toolExecutionNotifications =
51-
run.invocations[0].toolExecutionNotifications;
52+
if (toolExecutionNotifications === undefined) {
53+
throw new Error("toolExecutionNotifications is undefined");
54+
}
5255

53-
if (toolExecutionNotifications === undefined) {
54-
throw new Error("toolExecutionNotifications is undefined");
55-
}
56+
const statusPageNotifications = toolExecutionNotifications.filter(
57+
(n) =>
58+
n.descriptor?.id === DIAGNOSTIC_ID &&
59+
n.properties?.visibility?.statusPage,
60+
);
61+
if (statusPageNotifications.length !== 1) {
62+
core.setFailed(
63+
"Expected exactly one status page reporting descriptor for this diagnostic in the " +
64+
`'runs[].invocations[].toolExecutionNotifications[]' SARIF property, but found ` +
65+
`${statusPageNotifications.length}. All notification reporting descriptors: ` +
66+
`${JSON.stringify(toolExecutionNotifications)}.`,
67+
);
68+
}
69+
checkStatusPageNotification(statusPageNotifications[0]);
5670

57-
const statusPageNotifications = toolExecutionNotifications.filter(
58-
(n) =>
59-
n.descriptor?.id === DIAGNOSTIC_ID && n.properties?.visibility?.statusPage,
60-
);
61-
if (statusPageNotifications.length !== 1) {
62-
core.setFailed(
63-
"Expected exactly one status page reporting descriptor for this diagnostic in the " +
64-
`'runs[].invocations[].toolExecutionNotifications[]' SARIF property, but found ` +
65-
`${statusPageNotifications.length}. All notification reporting descriptors: ` +
66-
`${JSON.stringify(toolExecutionNotifications)}.`,
71+
const notifications = run.tool.driver.notifications;
72+
73+
if (notifications === undefined) {
74+
throw new Error("notifications is undefined");
75+
}
76+
77+
const diagnosticNotification = notifications.filter(
78+
(n) =>
79+
n.id === DIAGNOSTIC_ID &&
80+
n.name === DIAGNOSTIC_ID &&
81+
n.fullDescription?.text === DIAGNOSTIC_NAME,
6782
);
83+
if (diagnosticNotification.length !== 1) {
84+
core.setFailed(
85+
"Expected exactly one notification for this diagnostic in the " +
86+
`'runs[].tool.driver.notifications[]' SARIF property, but found ` +
87+
`${diagnosticNotification.length}. All notifications: ` +
88+
`${JSON.stringify(notifications)}.`,
89+
);
90+
}
6891
}
69-
checkStatusPageNotification(statusPageNotifications[0]);
7092

71-
const notifications = run.tool.driver.notifications;
93+
const sarifPath = process.env["SARIF_PATH"];
7294

73-
if (notifications === undefined) {
74-
throw new Error("notifications is undefined");
95+
if (sarifPath === undefined) {
96+
throw new Error(
97+
"The path to a SARIF file or directory must be set in 'SARIF_PATH'.",
98+
);
7599
}
76100

77-
const diagnosticNotification = notifications.filter(
78-
(n) =>
79-
n.id === DIAGNOSTIC_ID &&
80-
n.name === DIAGNOSTIC_ID &&
81-
n.fullDescription?.text === DIAGNOSTIC_NAME,
82-
);
83-
if (diagnosticNotification.length !== 1) {
84-
core.setFailed(
85-
"Expected exactly one notification for this diagnostic in the " +
86-
`'runs[].tool.driver.notifications[]' SARIF property, but found ` +
87-
`${diagnosticNotification.length}. All notifications: ` +
88-
`${JSON.stringify(notifications)}.`,
89-
);
101+
if (fs.statSync(sarifPath).isDirectory()) {
102+
const sarifFiles = globSync("**/*.sarif", {
103+
cwd: path.resolve(sarifPath),
104+
absolute: true,
105+
});
106+
107+
if (sarifFiles.length < 1) {
108+
throw new Error(`Unable to find any .sarif files in '${sarifPath}'.`);
109+
}
110+
111+
for (const sarifFile of sarifFiles) {
112+
checkSarif(sarifFile);
113+
}
114+
} else {
115+
checkSarif(sarifPath);
90116
}
91117

92118
core.info("Finished diagnostic export test");

‎pr-checks/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@octokit/core": "^7.0.8",
1010
"@octokit/plugin-paginate-rest": ">=16.0.0",
1111
"@octokit/plugin-rest-endpoint-methods": "^18.0.0",
12+
"glob": "^13.0.6",
1213
"lite-matter": "^0.1.2",
1314
"mdast-util-from-markdown": "^2.1.0",
1415
"semver": "^7.8.5",

‎src/actions-util.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const getOptionalInput = function (name: string): string | undefined {
7272
* directory that has been set in `CODEQL_ACTION_TEMP` by e.g. a previous step, or the
7373
* value of `RUNNER_TEMP` otherwise.
7474
*/
75-
export function getTemporaryDirectory(env: Env = getEnv()): string {
75+
export function getTemporaryDirectory(env: ReadOnlyEnv = getEnv()): string {
7676
return (
7777
env.getOptional(EnvVar.TEMP) ?? env.getRequired(ActionsEnvVars.RUNNER_TEMP)
7878
);
@@ -361,9 +361,10 @@ const MAX_STDERR_BUFFER_SIZE = 20000;
361361
* Runs a CLI tool.
362362
*
363363
* @returns Standard output produced by the tool.
364-
* @throws A `CommandInvocationError` if the tool exits with a non-zero status code.
364+
* @throws A {@link CommandInvocationError} if the tool exits with a non-zero status code.
365365
*/
366366
export async function runTool(
367+
env: Env,
367368
cmd: string,
368369
args: string[] = [],
369370
opts: { stdin?: string; noStreamStdout?: boolean } = {},
@@ -374,6 +375,7 @@ export async function runTool(
374375
process.stdout.write(`[command]${cmd} ${args.join(" ")}\n`);
375376
}
376377
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
378+
env: env.getDefined(),
377379
ignoreReturnCode: true,
378380
listeners: {
379381
stdout: (data: Buffer) => {

‎src/cli/output-cache.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
import path from "path";
33

44
import { getTemporaryDirectory } from "../actions-util";
5-
import { Env } from "../environment";
5+
import { ReadOnlyEnv } from "../environment";
66
import * as json from "../json";
77
import { Logger } from "../logging";
88

@@ -51,7 +51,7 @@ export function resetCachedCodeQlVersion(): void {
5151
* Returns the path to the temporary file that backs the
5252
* on-disk cache of CLI responses between workflow steps.
5353
*/
54-
export function getCommandCacheFilePath(env: Env): string {
54+
export function getCommandCacheFilePath(env: ReadOnlyEnv): string {
5555
return path.join(getTemporaryDirectory(env), COMMAND_CACHE_FILENAME);
5656
}
5757

0 commit comments

Comments
 (0)