Skip to content

Commit 05b2852

Browse files
committed
Stop saving config in initConfig()
1 parent 4e2e64a commit 05b2852

File tree

4 files changed

+7
-54
lines changed

4 files changed

+7
-54
lines changed

lib/init-action.js

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

src/config-utils.test.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -229,51 +229,6 @@ test("load code quality config", async (t) => {
229229
});
230230
});
231231

232-
test("loading config saves config", async (t) => {
233-
return await withTmpDir(async (tempDir) => {
234-
const logger = getRunnerLogger(true);
235-
236-
const codeql = createStubCodeQL({
237-
async betterResolveLanguages() {
238-
return {
239-
extractors: {
240-
javascript: [{ extractor_root: "" }],
241-
python: [{ extractor_root: "" }],
242-
},
243-
};
244-
},
245-
});
246-
247-
// Sanity check the saved config file does not already exist
248-
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
249-
250-
// Sanity check that getConfig returns undefined before we have called initConfig
251-
t.deepEqual(await configUtils.getConfig(tempDir, logger), undefined);
252-
253-
const config1 = await configUtils.initConfig(
254-
createTestInitConfigInputs({
255-
languagesInput: "javascript,python",
256-
tempDir,
257-
codeql,
258-
workspacePath: tempDir,
259-
logger,
260-
}),
261-
);
262-
263-
// The saved config file should now exist
264-
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
265-
266-
// And that same newly-initialised config should now be returned by getConfig
267-
const config2 = await configUtils.getConfig(tempDir, logger);
268-
t.not(config2, undefined);
269-
if (config2 !== undefined) {
270-
// removes properties assigned to undefined.
271-
const expectedConfig = JSON.parse(JSON.stringify(config1));
272-
t.deepEqual(expectedConfig, config2);
273-
}
274-
});
275-
});
276-
277232
test("loading config with version mismatch throws", async (t) => {
278233
return await withTmpDir(async (tempDir) => {
279234
const logger = getRunnerLogger(true);
@@ -300,7 +255,7 @@ test("loading config with version mismatch throws", async (t) => {
300255
.stub(actionsUtil, "getActionVersion")
301256
.returns("does-not-exist");
302257

303-
await configUtils.initConfig(
258+
const config = await configUtils.initConfig(
304259
createTestInitConfigInputs({
305260
languagesInput: "javascript,python",
306261
tempDir,
@@ -309,6 +264,8 @@ test("loading config with version mismatch throws", async (t) => {
309264
logger,
310265
}),
311266
);
267+
// initConfig does not save the config, so we do it here.
268+
await configUtils.saveConfig(config, logger);
312269

313270
// Restore `getActionVersion`.
314271
getActionVersionStub.restore();

src/config-utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,6 @@ export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
11891189
exclude: { tags: "exclude-from-incremental" },
11901190
});
11911191
}
1192-
1193-
// Save the config so we can easily access it again in the future
1194-
await saveConfig(config, logger);
11951192
return config;
11961193
}
11971194

src/init-action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,10 @@ async function run() {
681681
logUnwrittenDiagnostics();
682682
}
683683

684-
// We may have updated the config returned from `initConfig`, e.g. to revert
685-
// to `OverlayDatabaseMode.None` if we failed to download an overlay-base
686-
// database. So we save the config again, to ensure that the `analyze` step
687-
// reads the correct config.
684+
// We save the config here instead of at the end of `initConfig` because we
685+
// may have updated the config returned from `initConfig`, e.g. to revert to
686+
// `OverlayDatabaseMode.None` if we failed to download an overlay-base
687+
// database.
688688
await configUtils.saveConfig(config, logger);
689689
await sendCompletedStatusReport(
690690
startedAt,

0 commit comments

Comments
 (0)