Skip to content

Commit ac9f257

Browse files
committed
Merge remote-tracking branch 'origin/main' into mbg/refactor-util/errors
2 parents fb9d453 + 52cf185 commit ac9f257

12 files changed

Lines changed: 821 additions & 216 deletions

File tree

‎.github/workflows/pr-checks.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ jobs:
126126
if: ${{ !cancelled() && steps.install-deps.outcome == 'success' }}
127127
run: .github/workflows/script/verify-pr-checks.sh
128128

129+
- name: Typecheck pr-checks scripts
130+
if: ${{ !cancelled() && steps.install-deps.outcome == 'success' }}
131+
working-directory: pr-checks
132+
run: npm run typecheck
133+
129134
- name: Run pr-checks tests
130135
if: ${{ !cancelled() && steps.install-deps.outcome == 'success' }}
131136
working-directory: pr-checks
132-
run: npx tsx --test
137+
run: npm run test
133138

134139
- name: Run `pr-checks/changenotes.ts` to ensure that all unreleased change notes are valid
135140
if: ${{ !cancelled() && steps.install-deps.outcome == 'success' }}

‎lib/entry-points.js‎

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

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"test": "npm run ava -- src/",
1414
"test-debug": "npm run test -- --timeout=20m",
1515
"transpile": "tsc --build --verbose tsconfig.json",
16-
"update-pr-checks": "./pr-checks/sync.sh"
16+
"update-pr-checks": "./pr-checks/sync.sh",
17+
"typecheck": "tsc --noEmit"
1718
},
1819
"license": "MIT",
1920
"workspaces": [

‎pr-checks/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"private": true,
33
"description": "Dependencies for codeql-action scripts",
44
"type": "module",
5+
"scripts": {
6+
"typecheck": "tsc --noEmit",
7+
"test": "npx tsx --test",
8+
"checks": "npm run typecheck && npm run test"
9+
},
510
"dependencies": {
611
"@actions/core": "^2.0.3",
712
"@actions/github": "^8.0.1",

‎pr-checks/tsconfig.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
"noEmit": true
1010
},
1111
"include": ["./**/*.ts", "../src/**/*.ts"],
12-
"exclude": ["node_modules"]
12+
"exclude": [
13+
"node_modules",
14+
"../src/testdata/**",
15+
"../src/**/*.test.ts",
16+
"../src/testing-utils.ts",
17+
"../src/json/testing-util.ts",
18+
"../src/feature-flags/testing-util.ts"
19+
]
1320
}

‎src/languages/traced.test.ts‎

Lines changed: 177 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import fs from "fs";
22

3+
import type { ExecOptions } from "@actions/exec";
4+
import * as toolrunner from "@actions/exec/lib/toolrunner";
5+
import * as io from "@actions/io";
36
import test from "ava";
47
import * as sinon from "sinon";
58

@@ -344,41 +347,58 @@ test.serial(
344347
}),
345348
);
346349

347-
test("checkRunnerSupportsTracedAnalysis doesn't perform Xcode check on self-hosted runners", async (t) =>
348-
withTmpDir(async (tmpDir) => {
349-
const logger = new RecordingLogger();
350-
const env = getTestEnv();
351-
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
352-
env.set(ActionsEnvVars.RUNNER_ENVIRONMENT, "self-hosted");
353-
const features = createFeatures([Feature.CheckUnsupportedTracedAnalysis]);
350+
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
351+
test.serial(
352+
"checkRunnerSupportsTracedAnalysis doesn't add a diagnostic if Xcode version is supported",
353+
async (t) =>
354+
withTmpDir(async (tmpDir) => {
355+
const logger = new RecordingLogger();
356+
const env = getTestEnv();
357+
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
358+
const features = createFeatures([Feature.CheckUnsupportedTracedAnalysis]);
354359

355-
const codeql = await getCodeQLWithTracedStub(
356-
"codeql-for-testing",
357-
logger,
358-
env,
359-
);
360-
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
360+
const readlinkSync = sinon
361+
.stub(fs, "readlinkSync")
362+
.returns("/Applications/Xcode_26.0.app/Contents/Developer");
361363

362-
await checkRunnerSupportsTracedAnalysis(
363-
initAllState({
364+
const codeql = await getCodeQLWithTracedStub(
365+
"codeql-for-testing",
364366
logger,
365-
platform: "darwin",
366-
osRelease: "26.0.0",
367367
env,
368-
features,
369-
}),
370-
createTestConfig({ tempDir: tmpDir, languages: [BuiltInLanguage.go] }),
371-
codeql,
372-
);
368+
);
369+
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
373370

374-
checkExpectedLogMessages(t, logger.messages, [
375-
"Skipping traced analysis compatibility check for Xcode because we are on a self-hosted runner.",
376-
]);
377-
}));
371+
const addDiagnostic = sinon.stub(diagnostics, "addDiagnostic");
372+
373+
const config = createTestConfig({
374+
tempDir: tmpDir,
375+
languages: [BuiltInLanguage.swift],
376+
});
377+
await checkRunnerSupportsTracedAnalysis(
378+
initAllState({
379+
logger,
380+
platform: "darwin",
381+
osRelease: "26.0.0",
382+
env,
383+
features,
384+
}),
385+
config,
386+
codeql,
387+
);
388+
389+
t.is(readlinkSync.callCount, 1);
390+
t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]);
391+
392+
checkUnexpectedLogMessages(t, logger.messages, [
393+
"Traced analysis is not supported on Xcode 27",
394+
]);
395+
396+
t.is(addDiagnostic.callCount, 0);
397+
}),
398+
);
378399

379-
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
380400
test.serial(
381-
"checkRunnerSupportsTracedAnalysis doesn't add a diagnostic if Xcode version is supported",
401+
"checkRunnerSupportsTracedAnalysis attempts fallbacks if needed",
382402
async (t) =>
383403
withTmpDir(async (tmpDir) => {
384404
const logger = new RecordingLogger();
@@ -388,7 +408,17 @@ test.serial(
388408

389409
const readlinkSync = sinon
390410
.stub(fs, "readlinkSync")
391-
.returns("/Applications/Xcode_26.0.app/Contents/Developer");
411+
.throws(new Error("Not found"));
412+
const which = sinon.stub(io, "which").resolves("/path/to/xcrun");
413+
const exec = sinon.stub<[], Promise<number>>().callsFake(async () => {
414+
throw new Error("Error to force next fallback");
415+
});
416+
const runner = sinon.createStubInstance(toolrunner.ToolRunner, { exec });
417+
const toolrunnerStub = sinon
418+
.stub(toolrunner, "ToolRunner")
419+
.callsFake(() => {
420+
return runner;
421+
});
392422

393423
const codeql = await getCodeQLWithTracedStub(
394424
"codeql-for-testing",
@@ -417,7 +447,28 @@ test.serial(
417447

418448
t.is(readlinkSync.callCount, 1);
419449
t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]);
450+
t.is(which.callCount, 2);
451+
t.deepEqual(which.args[0], ["xcrun", true]);
452+
t.deepEqual(which.args[1], ["xcrun", true]);
453+
454+
t.is(toolrunnerStub.callCount, 2);
455+
t.is(exec.callCount, 2);
456+
457+
t.is(toolrunnerStub.args[0][0], "/path/to/xcrun");
458+
t.deepEqual(toolrunnerStub.args[0][1], ["xcodebuild", "-version"]);
420459

460+
t.is(toolrunnerStub.args[1][0], "/path/to/xcrun");
461+
t.deepEqual(toolrunnerStub.args[1][1], [
462+
"--sdk",
463+
"macosx",
464+
"--show-sdk-version",
465+
]);
466+
467+
checkExpectedLogMessages(t, logger.messages, [
468+
"Unable to determine Xcode version: Not found",
469+
"Unable to determine Xcode version from xcodebuild: Error to force next fallback",
470+
"Unable to determine Xcode SDK version: Error to force next fallback",
471+
]);
421472
checkUnexpectedLogMessages(t, logger.messages, [
422473
"Traced analysis is not supported on Xcode 27",
423474
]);
@@ -496,6 +547,103 @@ test.serial(
496547
}),
497548
);
498549

550+
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
551+
test.serial(
552+
"checkRunnerSupportsTracedAnalysis logs and adds diagnostic if Xcode SDK version is unsupported",
553+
async (t) =>
554+
withTmpDir(async (tmpDir) => {
555+
const logger = new RecordingLogger();
556+
const env = getTestEnv();
557+
env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir);
558+
const features = createFeatures([Feature.CheckUnsupportedTracedAnalysis]);
559+
560+
const readlinkSync = sinon
561+
.stub(fs, "readlinkSync")
562+
.throws(new Error("Not found"));
563+
const which = sinon.stub(io, "which").resolves("/path/to/xcrun");
564+
565+
let stdoutListener: ((data: Buffer) => void) | undefined = undefined;
566+
const exec = sinon.stub<[], Promise<number>>().callsFake(async () => {
567+
if (stdoutListener !== undefined) {
568+
stdoutListener(Buffer.from("27.5"));
569+
return 0;
570+
} else {
571+
throw new Error("Error to force next fallback");
572+
}
573+
});
574+
const runner = sinon.createStubInstance(toolrunner.ToolRunner, {
575+
exec,
576+
});
577+
const toolrunnerStub = sinon
578+
.stub(toolrunner, "ToolRunner")
579+
.callsFake((_cmd, args: string[], opts: ExecOptions) => {
580+
if (args[0] !== "xcodebuild") {
581+
stdoutListener = opts.listeners?.stdout;
582+
}
583+
return runner;
584+
});
585+
586+
const codeql = await getCodeQLWithTracedStub(
587+
"codeql-for-testing",
588+
logger,
589+
env,
590+
);
591+
sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0"));
592+
593+
const addDiagnostic = sinon.stub(diagnostics, "addDiagnostic");
594+
595+
const config = createTestConfig({
596+
tempDir: tmpDir,
597+
languages: [BuiltInLanguage.swift],
598+
});
599+
await checkRunnerSupportsTracedAnalysis(
600+
initAllState({
601+
logger,
602+
platform: "darwin",
603+
osRelease: "26.0.0",
604+
env,
605+
features,
606+
}),
607+
config,
608+
codeql,
609+
);
610+
611+
t.is(readlinkSync.callCount, 1);
612+
t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]);
613+
614+
t.is(which.callCount, 2);
615+
t.is(toolrunnerStub.callCount, 2);
616+
t.is(exec.callCount, 2);
617+
618+
checkExpectedLogMessages(t, logger.messages, [
619+
"Unable to determine Xcode version from xcodebuild",
620+
"Traced analysis is not supported on Xcode SDK 27",
621+
]);
622+
623+
t.is(addDiagnostic.callCount, 1);
624+
t.like(addDiagnostic.args[0], [
625+
config,
626+
BuiltInLanguage.swift,
627+
{
628+
attributes: {
629+
languages: [BuiltInLanguage.swift],
630+
xcodeSdkVersion: "27.5.0",
631+
},
632+
severity: "warning",
633+
source: {
634+
id: "codeql-action/unsupported-traced-analysis-xcode-sdk",
635+
name: "Traced analysis is not supported on this version of Xcode SDK",
636+
},
637+
visibility: {
638+
cliSummaryTable: true,
639+
statusPage: true,
640+
telemetry: true,
641+
},
642+
} satisfies Partial<diagnostics.DiagnosticMessage>,
643+
]);
644+
}),
645+
);
646+
499647
// `addDiagnostic` changes global state and we must stub it, so this test must be serial.
500648
test.serial(
501649
"checkRunnerSupportsTracedAnalysis throws if Xcode version is unsupported and FF is enabled",

0 commit comments

Comments
 (0)