Skip to content

Commit 54af742

Browse files
henrymercerCopilot
andcommitted
Simplify the condition for overlay-aware version selection
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 961c840 commit 54af742

3 files changed

Lines changed: 13 additions & 63 deletions

File tree

‎lib/entry-points.js‎

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

‎src/setup-codeql.test.ts‎

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,53 +1069,8 @@ async function fakeOverlayBaseCacheKey(
10691069
return `${prefix}${suffix}`;
10701070
}
10711071

1072-
for (const variant of [GitHubVariant.DOTCOM, GitHubVariant.GHEC_DR]) {
1073-
test.serial(
1074-
`getCodeQLSource uses overlay-aware default version for a Code Scanning PR on ${variant}`,
1075-
async (t) => {
1076-
await withTmpDir(async (tmpDir) => {
1077-
setupActionsVars(tmpDir, tmpDir);
1078-
process.env[EnvVar.CODE_SCANNING_REF] = "refs/heads/feature-branch";
1079-
process.env[EnvVar.CODE_SCANNING_BASE_BRANCH] = "main";
1080-
1081-
sinon.stub(api, "getAutomationID").resolves("test/");
1082-
const listStub = sinon.stub(api, "listActionsCaches").resolves([
1083-
{
1084-
key: await fakeOverlayBaseCacheKey(
1085-
"javascript",
1086-
"2.20.1",
1087-
"abc-1-1",
1088-
),
1089-
},
1090-
]);
1091-
sinon
1092-
.stub(toolcache, "find")
1093-
.withArgs("CodeQL", "2.20.1")
1094-
.returns("/path/to/codeql-2.20.1");
1095-
1096-
const source = await setupCodeql.getCodeQLSource(
1097-
undefined,
1098-
overlayMatchEnabledVersions,
1099-
["javascript"],
1100-
undefined, // otherLanguagePacksReason
1101-
true,
1102-
SAMPLE_DOTCOM_API_DETAILS,
1103-
variant,
1104-
false,
1105-
createFeatures([]),
1106-
getRunnerLogger(true),
1107-
);
1108-
1109-
t.assert(listStub.calledOnce);
1110-
t.is(source.sourceType, "toolcache");
1111-
t.is(source.toolsVersion, "2.20.1");
1112-
});
1113-
},
1114-
);
1115-
}
1116-
11171072
test.serial(
1118-
"getCodeQLSource skips overlay-aware default version for a Code Scanning PR on GHES",
1073+
"getCodeQLSource uses overlay-aware default version for a Code Scanning PR",
11191074
async (t) => {
11201075
await withTmpDir(async (tmpDir) => {
11211076
setupActionsVars(tmpDir, tmpDir);
@@ -1130,8 +1085,8 @@ test.serial(
11301085
]);
11311086
sinon
11321087
.stub(toolcache, "find")
1133-
.withArgs("CodeQL", "2.20.2")
1134-
.returns("/path/to/codeql-2.20.2");
1088+
.withArgs("CodeQL", "2.20.1")
1089+
.returns("/path/to/codeql-2.20.1");
11351090

11361091
const source = await setupCodeql.getCodeQLSource(
11371092
undefined,
@@ -1140,15 +1095,15 @@ test.serial(
11401095
undefined, // otherLanguagePacksReason
11411096
true,
11421097
SAMPLE_DOTCOM_API_DETAILS,
1143-
GitHubVariant.GHES,
1098+
GitHubVariant.DOTCOM,
11441099
false,
11451100
createFeatures([]),
11461101
getRunnerLogger(true),
11471102
);
11481103

1149-
t.assert(listStub.notCalled);
1104+
t.assert(listStub.calledOnce);
11501105
t.is(source.sourceType, "toolcache");
1151-
t.is(source.toolsVersion, "2.20.2");
1106+
t.is(source.toolsVersion, "2.20.1");
11521107
});
11531108
},
11541109
);

‎src/setup-codeql.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,19 @@ export async function getEnabledVersionsWithOverlayBaseDatabases(
220220

221221
/**
222222
* Resolves the newest enabled default CLI version that has a cached overlay-base database for the
223-
* relevant languages, if running a Code Scanning analysis for a pull request with multiple enabled
224-
* default versions in a supported environment and one exists. Otherwise, falls back to the newest
225-
* enabled default CLI version.
223+
* relevant languages, if this is a Code Scanning analysis of a pull request, multiple default
224+
* versions are enabled, and such a version exists. Otherwise, falls back to the newest enabled
225+
* default CLI version.
226226
*/
227227
async function resolveDefaultCliVersion(
228228
defaultCliVersion: CodeQLDefaultVersionInfo,
229229
rawLanguages: string[] | undefined,
230230
useOverlayAwareDefaultCliVersion: boolean,
231-
variant: util.GitHubVariant,
232231
logger: Logger,
233232
): Promise<CodeQLVersionInfo> {
234233
if (
235234
!useOverlayAwareDefaultCliVersion ||
236-
(variant !== util.GitHubVariant.DOTCOM &&
237-
variant !== util.GitHubVariant.GHEC_DR) ||
235+
// Listing the Actions cache can't change which version we use if only one version is enabled.
238236
defaultCliVersion.enabledVersions.length === 1 ||
239237
!isAnalyzingPullRequest()
240238
) {
@@ -440,7 +438,6 @@ export async function getCodeQLSource(
440438
defaultCliVersion,
441439
rawLanguages,
442440
useOverlayAwareDefaultCliVersion,
443-
variant,
444441
logger,
445442
);
446443
cliVersion = version.cliVersion;
@@ -463,7 +460,6 @@ export async function getCodeQLSource(
463460
defaultCliVersion,
464461
rawLanguages,
465462
useOverlayAwareDefaultCliVersion,
466-
variant,
467463
logger,
468464
);
469465
cliVersion = version.cliVersion;

0 commit comments

Comments
 (0)