Skip to content

Commit 8c16574

Browse files
committed
Make jsonFilePath an explicit input to functions in diff-informed/index.ts
1 parent 3a4f195 commit 8c16574

9 files changed

Lines changed: 81 additions & 49 deletions

File tree

‎lib/entry-points.js‎

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

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/analyze.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import * as io from "@actions/io";
66
import * as yaml from "js-yaml";
77

88
import type { ActionState } from "./action-common";
9-
import { getTemporaryDirectory } from "./actions-util";
9+
import {
10+
getDiffRangesJsonFilePath,
11+
getTemporaryDirectory,
12+
} from "./actions-util";
1013
import * as analyses from "./analyses";
1114
import { setupCppAutobuild } from "./autobuild";
1215
import { type CodeQL } from "./codeql";
@@ -292,7 +295,10 @@ export async function setupDiffInformedQueryRun(
292295
return await withGroupAsync(
293296
"Generating diff range extension pack",
294297
async () => {
295-
const diffRanges = readDiffRangesJsonFile(logger);
298+
const diffRanges = readDiffRangesJsonFile(
299+
logger,
300+
getDiffRangesJsonFilePath(),
301+
);
296302
if (diffRanges === undefined) {
297303
logger.info(
298304
"No precomputed diff ranges found; skipping diff-informed analysis stage.",

‎src/config-utils.test.ts‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { createStubCodeQL } from "./codeql";
1515
import { UserConfig } from "./config/db-config";
1616
import * as file from "./config/file";
1717
import * as configUtils from "./config-utils";
18+
import { ActionsEnvVars } from "./environment";
1819
import * as errorMessages from "./error-messages";
1920
import { Feature } from "./feature-flags";
2021
import { RepositoryProperties } from "./feature-flags/properties";
@@ -42,6 +43,7 @@ import {
4243
SAMPLE_DOTCOM_API_DETAILS,
4344
AssertableTarget,
4445
RecordingLogger,
46+
getTestEnv,
4547
} from "./testing-utils";
4648
import {
4749
GitHubVariant,
@@ -151,9 +153,11 @@ function mockListLanguages(languages: string[]) {
151153
test.serial("load empty config", async (t) => {
152154
return await withTmpDir(async (tempDir) => {
153155
const logger = new RecordingLogger();
156+
const state = initAllState({ logger });
157+
154158
const languages = "javascript,python";
155159

156-
setupActionsVars(tempDir, tempDir);
160+
setupActionsVars(tempDir, tempDir, {}, state.env);
157161

158162
const codeql = createStubCodeQL({
159163
async resolveLanguages() {
@@ -166,7 +170,6 @@ test.serial("load empty config", async (t) => {
166170
},
167171
});
168172

169-
const state = initAllState({ logger });
170173
const config = await configUtils.initConfig(
171174
state,
172175
createTestInitConfigInputs({
@@ -197,9 +200,10 @@ test.serial("load empty config", async (t) => {
197200
test.serial("load code quality config", async (t) => {
198201
return await withTmpDir(async (tempDir) => {
199202
const logger = new RecordingLogger();
203+
const state = initAllState({ logger });
200204
const languages = "actions";
201205

202-
setupActionsVars(tempDir, tempDir);
206+
setupActionsVars(tempDir, tempDir, {}, state.env);
203207

204208
const codeql = createStubCodeQL({
205209
async resolveLanguages() {
@@ -211,7 +215,6 @@ test.serial("load code quality config", async (t) => {
211215
},
212216
});
213217

214-
const state = initAllState({ logger });
215218
const config = await configUtils.initConfig(
216219
state,
217220
createTestInitConfigInputs({
@@ -253,9 +256,10 @@ test.serial(
253256
async (t) => {
254257
return await withTmpDir(async (tempDir) => {
255258
const logger = new RecordingLogger();
259+
const state = initAllState({ logger });
256260
const languages = "javascript";
257261

258-
setupActionsVars(tempDir, tempDir);
262+
setupActionsVars(tempDir, tempDir, {}, state.env);
259263

260264
const codeql = createStubCodeQL({
261265
async resolveLanguages() {
@@ -291,7 +295,6 @@ test.serial(
291295
repositoryProperties,
292296
});
293297

294-
const state = initAllState({ logger });
295298
await t.notThrowsAsync(async () => {
296299
const config = await configUtils.initConfig(
297300
state,
@@ -316,6 +319,8 @@ test.serial(
316319
test.serial("loading a saved config produces the same config", async (t) => {
317320
return await withTmpDir(async (tempDir) => {
318321
const logger = new RecordingLogger();
322+
const state = initAllState({ logger });
323+
setupActionsVars(tempDir, tempDir, {}, state.env);
319324

320325
const codeql = createStubCodeQL({
321326
async resolveLanguages() {
@@ -334,7 +339,6 @@ test.serial("loading a saved config produces the same config", async (t) => {
334339
// Sanity check that getConfig returns undefined before we have called initConfig
335340
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);
336341

337-
const state = initAllState({ logger });
338342
const config1 = await configUtils.initConfig(
339343
state,
340344
createTestInitConfigInputs({
@@ -364,6 +368,8 @@ test.serial("loading a saved config produces the same config", async (t) => {
364368
test.serial("loading config with version mismatch throws", async (t) => {
365369
return await withTmpDir(async (tempDir) => {
366370
const logger = new RecordingLogger();
371+
const state = initAllState({ logger });
372+
setupActionsVars(tempDir, tempDir, {}, state.env);
367373

368374
const codeql = createStubCodeQL({
369375
async resolveLanguages() {
@@ -387,7 +393,6 @@ test.serial("loading config with version mismatch throws", async (t) => {
387393
.stub(actionsUtil, "getActionVersion")
388394
.returns("does-not-exist");
389395

390-
const state = initAllState({ logger });
391396
const config = await configUtils.initConfig(
392397
state,
393398
createTestInitConfigInputs({
@@ -497,7 +502,8 @@ const otherConfigFileContents = `
497502

498503
test.serial("load non-empty input", async (t) => {
499504
return await withTmpDir(async (tempDir) => {
500-
setupActionsVars(tempDir, tempDir);
505+
const state = initAllState();
506+
setupActionsVars(tempDir, tempDir, {}, state.env);
501507

502508
const codeql = createStubCodeQL({
503509
async resolveLanguages() {
@@ -538,7 +544,6 @@ test.serial("load non-empty input", async (t) => {
538544
const languagesInput = "javascript";
539545
const configFilePath = createConfigFile(otherConfigFileContents, tempDir);
540546

541-
const state = initAllState();
542547
const actualConfig = await configUtils.initConfig(
543548
state,
544549
createTestInitConfigInputs({
@@ -657,7 +662,9 @@ test.serial("API client used when reading remote config", async (t) => {
657662
const configFile = "octo-org/codeql-config/config.yaml@main";
658663
const languagesInput = "javascript";
659664

660-
const state = initAllState();
665+
const state = initAllState({
666+
env: getTestEnv({ [ActionsEnvVars.RUNNER_TEMP]: tempDir }),
667+
});
661668
await configUtils.initConfig(
662669
state,
663670
createTestInitConfigInputs({

‎src/config-utils.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as yaml from "js-yaml";
77
import { ActionState } from "./action-common";
88
import {
99
getActionVersion,
10+
getDiffRangesJsonFilePath,
1011
getOptionalInput,
1112
isAnalyzingPullRequest,
1213
isDefaultSetup,
@@ -1288,9 +1289,10 @@ export async function initConfig(
12881289
}
12891290

12901291
const hasDiffRanges = await prepareDiffInformedAnalysis(
1291-
inputs.codeql,
1292-
inputs.features,
12931292
logger,
1293+
inputs.features,
1294+
inputs.codeql,
1295+
getDiffRangesJsonFilePath(actionState.env),
12941296
);
12951297

12961298
await applyIncrementalAnalysisSettings(

‎src/diff-informed/index.test.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as sinon from "sinon";
44
import * as actionsUtil from "../actions-util";
55
import type { PullRequestBranches } from "../actions-util";
66
import * as apiClient from "../api-client";
7+
import { getEnv } from "../environment";
78
import { Feature, FeatureEnablement, initFeatures } from "../feature-flags";
89
import { parseRepositoryNwo } from "../repository";
910
import {
@@ -193,9 +194,10 @@ test.serial(
193194
.resolves({ type: GitHubVariant.DOTCOM });
194195

195196
const result = await prepareDiffInformedAnalysis(
196-
codeql,
197-
features,
198197
logger,
198+
features,
199+
codeql,
200+
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
199201
);
200202

201203
t.false(result);
@@ -223,9 +225,10 @@ test.serial(
223225
};
224226

225227
const result = await prepareDiffInformedAnalysis(
226-
codeql,
227-
features,
228228
logger,
229+
features,
230+
codeql,
231+
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
229232
);
230233

231234
t.false(result);
@@ -260,9 +263,10 @@ test.serial(
260263
} as any);
261264

262265
const result = await prepareDiffInformedAnalysis(
263-
codeql,
264-
features,
265266
logger,
267+
features,
268+
codeql,
269+
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
266270
);
267271

268272
t.true(result);
@@ -297,9 +301,10 @@ test.serial(
297301
} as any);
298302

299303
const result = await prepareDiffInformedAnalysis(
300-
codeql,
301-
features,
302304
logger,
305+
features,
306+
codeql,
307+
actionsUtil.getDiffRangesJsonFilePath(getEnv()),
303308
);
304309

305310
t.false(result);

0 commit comments

Comments
 (0)