Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to keep this test if you now manually call saveConfig before this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stated purpose of the test is to verify that initConfig() saves the config file. After the suggested change, initConfig() no longer saves the config file.

Can you clarify how you would like to see this test saved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is more of a round-trip test: whether saving a config and then loading it results in the same object. It just so happened that initConfig was saving the config before, but not what was primarily being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,9 +1189,6 @@ export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
exclude: { tags: "exclude-from-incremental" },
});
}

// Save the config so we can easily access it again in the future
await saveConfig(config, logger);
return config;
}

Expand Down Expand Up @@ -1289,7 +1286,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 });
Expand Down
6 changes: 6 additions & 0 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ async function run() {
} finally {
logUnwrittenDiagnostics();
}

// 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,
config,
Expand Down
Loading