From 4e2e64a92a4b1f28841376f56459f1cf9390d39e Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Thu, 11 Sep 2025 08:07:50 -0700 Subject: [PATCH 1/2] init-action: save updated config This commit updates the init action to save the config again at the end of run(), so that config updates in run() are correctly propagated to the analyze action. --- lib/init-action.js | 1 + src/config-utils.ts | 2 +- src/init-action.ts | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/init-action.js b/lib/init-action.js index dbd5a8926f..dab7782f87 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90701,6 +90701,7 @@ exec ${goBinaryPath} "$@"` } finally { logUnwrittenDiagnostics(); } + await saveConfig(config, logger); await sendCompletedStatusReport( startedAt, config, diff --git a/src/config-utils.ts b/src/config-utils.ts index 7bdc29a2e2..c84e9ecfc6 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -1289,7 +1289,7 @@ export function getPathToParsedConfigFile(tempDir: string): string { /** * Store the given config to the path returned from getPathToParsedConfigFile. */ -async function saveConfig(config: Config, logger: Logger) { +export async function saveConfig(config: Config, logger: Logger) { const configString = JSON.stringify(config); const configFile = getPathToParsedConfigFile(config.tempDir); fs.mkdirSync(path.dirname(configFile), { recursive: true }); diff --git a/src/init-action.ts b/src/init-action.ts index 8c9e2f36b8..4e9446b849 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -680,6 +680,12 @@ async function run() { } finally { logUnwrittenDiagnostics(); } + + // We may have updated the config returned from `initConfig`, e.g. to revert + // to `OverlayDatabaseMode.None` if we failed to download an overlay-base + // database. So we save the config again, to ensure that the `analyze` step + // reads the correct config. + await configUtils.saveConfig(config, logger); await sendCompletedStatusReport( startedAt, config, From 5c30ae46c128cd17cd9e481541d335b9e7bb4e68 Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Thu, 11 Sep 2025 12:31:29 -0700 Subject: [PATCH 2/2] Stop saving config in initConfig() --- lib/init-action.js | 1 - src/config-utils.test.ts | 7 +++++-- src/config-utils.ts | 3 --- src/init-action.ts | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index dab7782f87..2092324277 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -87687,7 +87687,6 @@ async function initConfig(inputs) { exclude: { tags: "exclude-from-incremental" } }); } - await saveConfig(config, logger); return config; } function parseRegistries(registriesInput) { diff --git a/src/config-utils.test.ts b/src/config-utils.test.ts index f2aa21d121..bc7307c19f 100644 --- a/src/config-utils.test.ts +++ b/src/config-utils.test.ts @@ -229,7 +229,7 @@ test("load code quality config", async (t) => { }); }); -test("loading config saves config", async (t) => { +test("loading a saved config produces the same config", async (t) => { return await withTmpDir(async (tempDir) => { const logger = getRunnerLogger(true); @@ -259,6 +259,7 @@ test("loading config saves config", async (t) => { logger, }), ); + await configUtils.saveConfig(config1, logger); // The saved config file should now exist t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir))); @@ -300,7 +301,7 @@ test("loading config with version mismatch throws", async (t) => { .stub(actionsUtil, "getActionVersion") .returns("does-not-exist"); - await configUtils.initConfig( + const config = await configUtils.initConfig( createTestInitConfigInputs({ languagesInput: "javascript,python", tempDir, @@ -309,6 +310,8 @@ test("loading config with version mismatch throws", async (t) => { logger, }), ); + // initConfig does not save the config, so we do it here. + await configUtils.saveConfig(config, logger); // Restore `getActionVersion`. getActionVersionStub.restore(); diff --git a/src/config-utils.ts b/src/config-utils.ts index c84e9ecfc6..93a3cce476 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -1189,9 +1189,6 @@ export async function initConfig(inputs: InitConfigInputs): Promise { exclude: { tags: "exclude-from-incremental" }, }); } - - // Save the config so we can easily access it again in the future - await saveConfig(config, logger); return config; } diff --git a/src/init-action.ts b/src/init-action.ts index 4e9446b849..aa97b65fcb 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -681,10 +681,10 @@ async function run() { logUnwrittenDiagnostics(); } - // We may have updated the config returned from `initConfig`, e.g. to revert - // to `OverlayDatabaseMode.None` if we failed to download an overlay-base - // database. So we save the config again, to ensure that the `analyze` step - // reads the correct config. + // We save the config here instead of at the end of `initConfig` because we + // may have updated the config returned from `initConfig`, e.g. to revert to + // `OverlayDatabaseMode.None` if we failed to download an overlay-base + // database. await configUtils.saveConfig(config, logger); await sendCompletedStatusReport( startedAt,