mirror of
https://github.com/github/codeql-action.git
synced 2026-11-05 04:29:40 +00:00
Simplify the condition for overlay-aware version selection
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
7
lib/entry-points.js
generated
7
lib/entry-points.js
generated
@@ -176305,8 +176305,9 @@ async function getEnabledVersionsWithOverlayBaseDatabases(defaultCliVersion, raw
|
||||
(v) => cachedVersionsSet.has(v.cliVersion)
|
||||
);
|
||||
}
|
||||
async function resolveDefaultCliVersion(defaultCliVersion, rawLanguages, useOverlayAwareDefaultCliVersion, variant, logger2) {
|
||||
if (!useOverlayAwareDefaultCliVersion || variant !== "GitHub.com" /* DOTCOM */ && variant !== "GitHub Enterprise Cloud with data residency" /* GHEC_DR */ || defaultCliVersion.enabledVersions.length === 1 || !isAnalyzingPullRequest()) {
|
||||
async function resolveDefaultCliVersion(defaultCliVersion, rawLanguages, useOverlayAwareDefaultCliVersion, logger2) {
|
||||
if (!useOverlayAwareDefaultCliVersion || // Listing the Actions cache can't change which version we use if only one version is enabled.
|
||||
defaultCliVersion.enabledVersions.length === 1 || !isAnalyzingPullRequest()) {
|
||||
return defaultCliVersion.enabledVersions[0];
|
||||
}
|
||||
const overlayVersions = await getEnabledVersionsWithOverlayBaseDatabases(
|
||||
@@ -176418,7 +176419,6 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, othe
|
||||
defaultCliVersion,
|
||||
rawLanguages,
|
||||
useOverlayAwareDefaultCliVersion,
|
||||
variant,
|
||||
logger2
|
||||
);
|
||||
cliVersion2 = version.cliVersion;
|
||||
@@ -176438,7 +176438,6 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, othe
|
||||
defaultCliVersion,
|
||||
rawLanguages,
|
||||
useOverlayAwareDefaultCliVersion,
|
||||
variant,
|
||||
logger2
|
||||
);
|
||||
cliVersion2 = version.cliVersion;
|
||||
|
||||
@@ -1069,53 +1069,8 @@ async function fakeOverlayBaseCacheKey(
|
||||
return `${prefix}${suffix}`;
|
||||
}
|
||||
|
||||
for (const variant of [GitHubVariant.DOTCOM, GitHubVariant.GHEC_DR]) {
|
||||
test.serial(
|
||||
`getCodeQLSource uses overlay-aware default version for a Code Scanning PR on ${variant}`,
|
||||
async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
process.env[EnvVar.CODE_SCANNING_REF] = "refs/heads/feature-branch";
|
||||
process.env[EnvVar.CODE_SCANNING_BASE_BRANCH] = "main";
|
||||
|
||||
sinon.stub(api, "getAutomationID").resolves("test/");
|
||||
const listStub = sinon.stub(api, "listActionsCaches").resolves([
|
||||
{
|
||||
key: await fakeOverlayBaseCacheKey(
|
||||
"javascript",
|
||||
"2.20.1",
|
||||
"abc-1-1",
|
||||
),
|
||||
},
|
||||
]);
|
||||
sinon
|
||||
.stub(toolcache, "find")
|
||||
.withArgs("CodeQL", "2.20.1")
|
||||
.returns("/path/to/codeql-2.20.1");
|
||||
|
||||
const source = await setupCodeql.getCodeQLSource(
|
||||
undefined,
|
||||
overlayMatchEnabledVersions,
|
||||
["javascript"],
|
||||
undefined, // otherLanguagePacksReason
|
||||
true,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
variant,
|
||||
false,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
t.assert(listStub.calledOnce);
|
||||
t.is(source.sourceType, "toolcache");
|
||||
t.is(source.toolsVersion, "2.20.1");
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
test.serial(
|
||||
"getCodeQLSource skips overlay-aware default version for a Code Scanning PR on GHES",
|
||||
"getCodeQLSource uses overlay-aware default version for a Code Scanning PR",
|
||||
async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
@@ -1130,8 +1085,8 @@ test.serial(
|
||||
]);
|
||||
sinon
|
||||
.stub(toolcache, "find")
|
||||
.withArgs("CodeQL", "2.20.2")
|
||||
.returns("/path/to/codeql-2.20.2");
|
||||
.withArgs("CodeQL", "2.20.1")
|
||||
.returns("/path/to/codeql-2.20.1");
|
||||
|
||||
const source = await setupCodeql.getCodeQLSource(
|
||||
undefined,
|
||||
@@ -1140,15 +1095,15 @@ test.serial(
|
||||
undefined, // otherLanguagePacksReason
|
||||
true,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.GHES,
|
||||
GitHubVariant.DOTCOM,
|
||||
false,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
t.assert(listStub.notCalled);
|
||||
t.assert(listStub.calledOnce);
|
||||
t.is(source.sourceType, "toolcache");
|
||||
t.is(source.toolsVersion, "2.20.2");
|
||||
t.is(source.toolsVersion, "2.20.1");
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -220,21 +220,19 @@ export async function getEnabledVersionsWithOverlayBaseDatabases(
|
||||
|
||||
/**
|
||||
* Resolves the newest enabled default CLI version that has a cached overlay-base database for the
|
||||
* relevant languages, if running a Code Scanning analysis for a pull request with multiple enabled
|
||||
* default versions in a supported environment and one exists. Otherwise, falls back to the newest
|
||||
* enabled default CLI version.
|
||||
* relevant languages, if this is a Code Scanning analysis of a pull request, multiple default
|
||||
* versions are enabled, and such a version exists. Otherwise, falls back to the newest enabled
|
||||
* default CLI version.
|
||||
*/
|
||||
async function resolveDefaultCliVersion(
|
||||
defaultCliVersion: CodeQLDefaultVersionInfo,
|
||||
rawLanguages: string[] | undefined,
|
||||
useOverlayAwareDefaultCliVersion: boolean,
|
||||
variant: util.GitHubVariant,
|
||||
logger: Logger,
|
||||
): Promise<CodeQLVersionInfo> {
|
||||
if (
|
||||
!useOverlayAwareDefaultCliVersion ||
|
||||
(variant !== util.GitHubVariant.DOTCOM &&
|
||||
variant !== util.GitHubVariant.GHEC_DR) ||
|
||||
// Listing the Actions cache can't change which version we use if only one version is enabled.
|
||||
defaultCliVersion.enabledVersions.length === 1 ||
|
||||
!isAnalyzingPullRequest()
|
||||
) {
|
||||
@@ -440,7 +438,6 @@ export async function getCodeQLSource(
|
||||
defaultCliVersion,
|
||||
rawLanguages,
|
||||
useOverlayAwareDefaultCliVersion,
|
||||
variant,
|
||||
logger,
|
||||
);
|
||||
cliVersion = version.cliVersion;
|
||||
@@ -463,7 +460,6 @@ export async function getCodeQLSource(
|
||||
defaultCliVersion,
|
||||
rawLanguages,
|
||||
useOverlayAwareDefaultCliVersion,
|
||||
variant,
|
||||
logger,
|
||||
);
|
||||
cliVersion = version.cliVersion;
|
||||
|
||||
Reference in New Issue
Block a user