Skip to content

Commit c252c71

Browse files
committed
Move initializeEnvironment out of util.ts
1 parent a234b84 commit c252c71

17 files changed

Lines changed: 93 additions & 80 deletions

‎lib/entry-points.js‎

Lines changed: 30 additions & 18 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
@@ -12,8 +12,8 @@ import {
1212
import { computeAutomationID } from "./api-client";
1313
import { EnvVar } from "./environment";
1414
import { getRunnerLogger } from "./logging";
15-
import { RecordingLogger, setupTests } from "./testing-utils";
16-
import { initializeEnvironment, withTmpDir } from "./util";
15+
import { getTestEnv, RecordingLogger, setupTests } from "./testing-utils";
16+
import { withTmpDir } from "./util";
1717

1818
setupTests(test);
1919

@@ -228,8 +228,9 @@ test.serial(
228228
);
229229

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

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

‎src/analyze-action.ts‎

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

240240
try {
241-
util.initializeEnvironment(actionsUtil.getActionVersion());
241+
action.env.initialise(actionsUtil.getActionVersion());
242242

243243
// Make inputs accessible in the `post` step, details at
244244
// 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 { getRunnerLogger } from "./logging";
2627
import { ToolsSource } from "./setup-codeql";
@@ -37,14 +38,13 @@ import {
3738
} from "./testing-utils";
3839
import { ToolsDownloadStatusReport } from "./tools-download";
3940
import * as util from "./util";
40-
import { initializeEnvironment } from "./util";
4141

4242
setupTests(test);
4343

4444
let stubConfig: Config;
4545

4646
test.beforeEach(() => {
47-
initializeEnvironment("1.2.3");
47+
getEnv().initialise("1.2.3");
4848

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

‎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
@@ -371,6 +371,18 @@ export class Env extends ReadOnlyEnv {
371371
}
372372
}
373373

374+
/**
375+
* Set some initial environment variables that we can set even without
376+
* knowing what version of CodeQL we're running.
377+
*/
378+
public initialise(version: string) {
379+
this.export(EnvVar.FEATURE_MULTI_LANGUAGE, "false");
380+
this.export(EnvVar.FEATURE_SANDWICH, "false");
381+
this.export(EnvVar.FEATURE_SARIF_COMBINE, "true");
382+
this.export(EnvVar.FEATURE_WILL_UPLOAD, "true");
383+
this.export(EnvVar.VERSION, version);
384+
}
385+
374386
/** Gets a value indicating whether `set` was called at least once. */
375387
public hasChanged(): boolean {
376388
return this.changed;

‎src/feature-flags.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import test from "ava";
55

66
import * as defaults from "./defaults.json";
7+
import { getEnv } from "./environment";
78
import {
89
Feature,
910
featureConfig,
@@ -26,12 +27,12 @@ import {
2627
setupTests,
2728
stubFeatureFlagApiEndpoint,
2829
} from "./testing-utils";
29-
import { GitHubVariant, initializeEnvironment, withTmpDir } from "./util";
30+
import { GitHubVariant, withTmpDir } from "./util";
3031

3132
setupTests(test);
3233

3334
test.beforeEach(() => {
34-
initializeEnvironment("1.2.3");
35+
getEnv().initialise("1.2.3");
3536
});
3637

3738
test.serial(

‎src/feature-flags/offline-features.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
LoggedMessage,
99
setupTests,
1010
} from "../testing-utils";
11-
import { GitHubVariant, initializeEnvironment, withTmpDir } from "../util";
11+
import { getEnv, GitHubVariant, withTmpDir } from "../util";
1212

1313
import {
1414
assertAllFeaturesHaveDefaultValues,
@@ -18,7 +18,7 @@ import {
1818
setupTests(test);
1919

2020
test.beforeEach(() => {
21-
initializeEnvironment("1.2.3");
21+
getEnv().initialise("1.2.3");
2222
});
2323

2424
test("OfflineFeatures makes no API requests", async (t) => {

0 commit comments

Comments
 (0)