Skip to content

Commit 750fe8f

Browse files
authored
Merge branch 'main' into update-bundle/codeql-bundle-v2.27.4
2 parents adfcd5f + b35c6c6 commit 750fe8f

24 files changed

Lines changed: 361 additions & 324 deletions

‎lib/entry-points.js‎

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

‎src/actions-util.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
} from "./actions-util";
1212
import { computeAutomationID } from "./api-client";
1313
import { EnvVar } from "./environment";
14-
import { RecordingLogger, setupTests } from "./testing-utils";
15-
import { initializeEnvironment, withTmpDir } from "./util";
14+
import { getTestEnv, RecordingLogger, setupTests } from "./testing-utils";
15+
import { withTmpDir } from "./util";
1616

1717
setupTests(test);
1818

@@ -227,8 +227,9 @@ test.serial(
227227
);
228228

229229
test.serial("initializeEnvironment", (t) => {
230-
initializeEnvironment("1.2.3");
231-
t.deepEqual(process.env[EnvVar.VERSION], "1.2.3");
230+
const env = getTestEnv();
231+
env.initialise("1.2.3");
232+
t.deepEqual(env.getOptional(EnvVar.VERSION), "1.2.3");
232233
});
233234

234235
test.serial("fixCodeQualityCategory", (t) => {

‎src/analyze-action.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async function run(action: ActionState<["Base", "Logger", "Env", "Actions"]>) {
233233
let databaseUploadResults: DatabaseUploadResult[] = [];
234234

235235
try {
236-
util.initializeEnvironment(actionsUtil.getActionVersion());
236+
action.env.initialise(actionsUtil.getActionVersion());
237237

238238
// Make inputs accessible in the `post` step, details at
239239
// https://github.com/github/codeql-action/issues/2553

‎src/api-client.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ProxyAgent } from "undici";
77
import * as actionsUtil from "./actions-util";
88
import * as api from "./api-client";
99
import { DO_NOT_RETRY_STATUSES } from "./api-client";
10-
import { ActionsEnvVars, RegistryProxyVars } from "./environment";
10+
import { ActionsEnvVars, RegistryProxyVars, getEnv } from "./environment";
1111
import { GITHUB_DOTCOM_API_URL, GITHUB_DOTCOM_URL } from "./github";
1212
import {
1313
callee,
@@ -21,7 +21,7 @@ import * as util from "./util";
2121
setupTests(test);
2222

2323
test.beforeEach(() => {
24-
util.initializeEnvironment(actionsUtil.getActionVersion());
24+
getEnv().initialise(actionsUtil.getActionVersion());
2525
});
2626

2727
test.serial("getApiClient", async (t) => {

‎src/autobuild-action.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getGitHubVersion } from "./api-client";
1010
import { determineAutobuildLanguages, runAutobuild } from "./autobuild";
1111
import { getCodeQL } from "./codeql";
1212
import { Config, getConfig } from "./config-utils";
13-
import { EnvVar } from "./environment";
13+
import { EnvVar, type Env } from "./environment";
1414
import { Language } from "./languages";
1515
import { Logger } from "./logging";
1616
import {
@@ -26,7 +26,6 @@ import {
2626
checkDiskUsage,
2727
checkGitHubVersionInRange,
2828
ConfigurationError,
29-
initializeEnvironment,
3029
wrapError,
3130
} from "./util";
3231

@@ -38,14 +37,15 @@ interface AutobuildStatusReport extends StatusReportBase {
3837
}
3938

4039
async function sendCompletedStatusReport(
40+
env: Env,
4141
config: Config | undefined,
4242
logger: Logger,
4343
startedAt: Date,
4444
allLanguages: string[],
4545
failingLanguage?: string,
4646
cause?: Error,
4747
) {
48-
initializeEnvironment(getActionVersion());
48+
env.initialise(getActionVersion());
4949

5050
const status = getActionsStatus(cause, failingLanguage);
5151
const statusReportBase = await createStatusReportBase(
@@ -129,6 +129,7 @@ async function run({
129129
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${error.message}`,
130130
);
131131
await sendCompletedStatusReport(
132+
env,
132133
config,
133134
logger,
134135
startedAt,
@@ -141,7 +142,13 @@ async function run({
141142

142143
env.export(EnvVar.AUTOBUILD_DID_COMPLETE_SUCCESSFULLY, "true");
143144

144-
await sendCompletedStatusReport(config, logger, startedAt, languages ?? []);
145+
await sendCompletedStatusReport(
146+
env,
147+
config,
148+
logger,
149+
startedAt,
150+
languages ?? [],
151+
);
145152
}
146153

147154
/** Defines the `autobuild` Action. */

‎src/codeql.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import type { Config } from "./config-utils";
2222
import * as defaults from "./defaults.json";
2323
import { DocUrl } from "./doc-url";
24+
import { getEnv } from "./environment";
2425
import { BuiltInLanguage } from "./languages";
2526
import { ToolsSource } from "./setup-codeql";
2627
import {
@@ -38,14 +39,13 @@ import {
3839
} from "./testing-utils";
3940
import { ToolsDownloadStatusReport } from "./tools-download";
4041
import * as util from "./util";
41-
import { initializeEnvironment } from "./util";
4242

4343
setupTests(test);
4444

4545
let stubConfig: Config;
4646

4747
test.beforeEach(() => {
48-
initializeEnvironment("1.2.3");
48+
getEnv().initialise("1.2.3");
4949

5050
stubConfig = createTestConfig({
5151
languages: [BuiltInLanguage.cpp],

‎src/codeql.ts‎

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import * as core from "@actions/core";
55
import * as toolrunner from "@actions/exec/lib/toolrunner";
66
import * as yaml from "js-yaml";
7+
import * as semver from "semver";
78

89
import {
910
CommandInvocationError,
@@ -19,6 +20,7 @@ import type { ActionConfig } from "./config/action-config";
1920
import { appendExtraQueryExclusions, type Config } from "./config-utils";
2021
import { DocUrl } from "./doc-url";
2122
import { EnvVar, getEnv, Env, ReadOnlyEnv } from "./environment";
23+
import { getErrorMessage, isDiskConfigurationError } from "./errors";
2224
import {
2325
CodeQLDefaultVersionInfo,
2426
Feature,
@@ -34,7 +36,9 @@ import { ToolsDownloadStatusReport } from "./tools-download";
3436
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
3537
import { shouldEnableIndirectTracing } from "./tracer-config";
3638
import * as util from "./util";
37-
import { BuildMode, CleanupLevel, getErrorMessage } from "./util";
39+
import { BuildMode, CleanupLevel } from "./util";
40+
41+
export { isDiskConfigurationError } from "./errors";
3842

3943
type Options = Array<string | number | boolean>;
4044

@@ -70,6 +74,11 @@ export interface CodeQL {
7074
* Get a string containing the semver version of the CodeQL executable.
7175
*/
7276
getVersion(): Promise<VersionInfo>;
77+
/**
78+
* Determines whether the CLI installation represented by this {@link CodeQL} instance
79+
* has at least the {@link requiredVersion}.
80+
*/
81+
isVersionAtLeast(requiredVersion: string): Promise<boolean>;
7382
/**
7483
* Print version information about CodeQL.
7584
*/
@@ -275,26 +284,6 @@ const GHES_MOST_RECENT_DEPRECATION_DATE = "2026-10-16";
275284
/** The CLI verbosity level to use for extraction in debug mode. */
276285
const EXTRACTION_DEBUG_MODE_VERBOSITY = "progress++";
277286

278-
/**
279-
* Decides whether `e` is a disk-related error outside of our control
280-
* that should be classified as a `ConfigurationError`.
281-
*
282-
* @param e The error to check.
283-
* @returns True if the error should be treated as a `ConfigurationError` or false if not.
284-
*/
285-
export function isDiskConfigurationError(e: unknown): boolean {
286-
if (!(e instanceof Error)) {
287-
return false;
288-
}
289-
290-
return (
291-
// out of disk space
292-
e.message.includes("ENOSPC") ||
293-
// access denied
294-
e.message.includes("EACCES")
295-
);
296-
}
297-
298287
/**
299288
* Set up CodeQL CLI access.
300289
*
@@ -403,9 +392,9 @@ export function setCodeQL(codeql: Partial<CodeQL>): void {
403392
cachedCodeQL = createStubCodeQL(codeql);
404393
}
405394

406-
function resolveFunction<T>(
395+
function resolveFunction<K extends keyof CodeQL, T extends CodeQL[K]>(
407396
partialCodeql: Partial<CodeQL>,
408-
methodName: string,
397+
methodName: K,
409398
defaultImplementation?: T,
410399
): T {
411400
if (typeof partialCodeql[methodName] !== "function") {
@@ -415,7 +404,7 @@ function resolveFunction<T>(
415404
const dummyMethod = () => {
416405
throw new Error(`CodeQL ${methodName} method not correctly defined`);
417406
};
418-
return dummyMethod as T;
407+
return dummyMethod as unknown as T;
419408
}
420409
return partialCodeql[methodName] as T;
421410
}
@@ -432,6 +421,19 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
432421
getVersion: resolveFunction(partialCodeql, "getVersion", async () => ({
433422
version: "1.0.0",
434423
})),
424+
isVersionAtLeast: resolveFunction(
425+
partialCodeql,
426+
"isVersionAtLeast",
427+
async (requiredVersion) => {
428+
return (
429+
!!partialCodeql.getVersion &&
430+
semver.gte(
431+
(await partialCodeql.getVersion()).version,
432+
requiredVersion,
433+
)
434+
);
435+
},
436+
),
435437
printVersion: resolveFunction(partialCodeql, "printVersion"),
436438
supportsFeature: resolveFunction(
437439
partialCodeql,
@@ -525,6 +527,9 @@ export async function getCodeQLForCmd(
525527
}
526528
return result;
527529
},
530+
async isVersionAtLeast(requiredVersion: string) {
531+
return semver.gte((await this.getVersion()).version, requiredVersion);
532+
},
528533
async printVersion() {
529534
// Reuse the cached version information rather than invoking the CLI again.
530535
core.info(JSON.stringify(await this.getVersion(), null, 2));
@@ -1062,7 +1067,7 @@ export async function getCodeQLForCmd(
10621067
// CodeQL object is created.
10631068
if (
10641069
checkVersion &&
1065-
!(await util.codeQlVersionAtLeast(codeql, CODEQL_MINIMUM_VERSION))
1070+
!(await codeql.isVersionAtLeast(CODEQL_MINIMUM_VERSION))
10661071
) {
10671072
throw new util.ConfigurationError(
10681073
`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${
@@ -1072,7 +1077,7 @@ export async function getCodeQLForCmd(
10721077
} else if (
10731078
checkVersion &&
10741079
env.getOptional(EnvVar.SUPPRESS_DEPRECATED_SOON_WARNING) !== "true" &&
1075-
!(await util.codeQlVersionAtLeast(codeql, CODEQL_NEXT_MINIMUM_VERSION))
1080+
!(await codeql.isVersionAtLeast(CODEQL_NEXT_MINIMUM_VERSION))
10761081
) {
10771082
const result = await codeql.getVersion();
10781083
core.warning(

‎src/config-utils.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ import {
8282
GitHubVersion,
8383
ConfigurationError,
8484
BuildMode,
85-
codeQlVersionAtLeast,
8685
cloneObject,
8786
isDefined,
8887
checkDiskUsage,
@@ -654,10 +653,7 @@ async function runnerHasSufficientMemory(
654653
logger: Logger,
655654
): Promise<boolean> {
656655
if (
657-
await codeQlVersionAtLeast(
658-
codeql,
659-
CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE,
660-
)
656+
await codeql.isVersionAtLeast(CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE)
661657
) {
662658
logger.debug(
663659
`Skipping memory check for overlay analysis because CodeQL version is at least ${CODEQL_VERSION_REDUCED_OVERLAY_MEMORY_USAGE}.`,
@@ -901,7 +897,7 @@ async function validateOverlayDatabaseMode(
901897
);
902898
return new Failure(OverlayDisabledReason.IncompatibleBuildMode);
903899
}
904-
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
900+
if (!(await codeql.isVersionAtLeast(CODEQL_OVERLAY_MINIMUM_VERSION))) {
905901
logger.warning(
906902
`Cannot build an ${overlayDatabaseMode} database because ` +
907903
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +

‎src/database-upload.test.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
cleanupAndUploadDatabases,
1616
uploadBundledDatabase,
1717
} from "./database-upload";
18+
import { getEnv } from "./environment";
1819
import { Feature } from "./feature-flags";
1920
import * as gitUtils from "./git-utils";
2021
import { BuiltInLanguage } from "./languages";
@@ -31,18 +32,12 @@ import {
3132
setupActionsVars,
3233
setupTests,
3334
} from "./testing-utils";
34-
import {
35-
CleanupLevel,
36-
GitHubVariant,
37-
HTTPError,
38-
initializeEnvironment,
39-
withTmpDir,
40-
} from "./util";
35+
import { CleanupLevel, GitHubVariant, HTTPError, withTmpDir } from "./util";
4136

4237
setupTests(test);
4338

4439
test.beforeEach(() => {
45-
initializeEnvironment("1.2.3");
40+
getEnv().initialise("1.2.3");
4641
});
4742

4843
const testRepoName: RepositoryNwo = { owner: "github", repo: "example" };

‎src/environment.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@ export class Env extends ReadOnlyEnv {
397397
}
398398
}
399399

400+
/**
401+
* Set some initial environment variables that we can set even without
402+
* knowing what version of CodeQL we're running.
403+
*/
404+
public initialise(version: string) {
405+
this.export(EnvVar.FEATURE_MULTI_LANGUAGE, "false");
406+
this.export(EnvVar.FEATURE_SANDWICH, "false");
407+
this.export(EnvVar.FEATURE_SARIF_COMBINE, "true");
408+
this.export(EnvVar.FEATURE_WILL_UPLOAD, "true");
409+
this.export(EnvVar.VERSION, version);
410+
}
411+
400412
/** Gets a value indicating whether `set` was called at least once. */
401413
public hasChanged(): boolean {
402414
return this.changed;

0 commit comments

Comments
 (0)