Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d33fd9

Browse files
authored
Merge pull request #3109 from github/cklin/init-save-updated-config
init-action: save updated config
2 parents 148e76a + 5c30ae4 commit 0d33fd9

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

lib/init-action.js

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/config-utils.test.ts

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

232-
test("loading config saves config", async (t) => {
232+
test("loading a saved config produces the same config", async (t) => {
233233
return await withTmpDir(async (tempDir) => {
234234
const logger = getRunnerLogger(true);
235235

@@ -259,6 +259,7 @@ test("loading config saves config", async (t) => {
259259
logger,
260260
}),
261261
);
262+
await configUtils.saveConfig(config1, logger);
262263

263264
// The saved config file should now exist
264265
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tempDir)));
@@ -300,7 +301,7 @@ test("loading config with version mismatch throws", async (t) => {
300301
.stub(actionsUtil, "getActionVersion")
301302
.returns("does-not-exist");
302303

303-
await configUtils.initConfig(
304+
const config = await configUtils.initConfig(
304305
createTestInitConfigInputs({
305306
languagesInput: "javascript,python",
306307
tempDir,
@@ -309,6 +310,8 @@ test("loading config with version mismatch throws", async (t) => {
309310
logger,
310311
}),
311312
);
313+
// initConfig does not save the config, so we do it here.
314+
await configUtils.saveConfig(config, logger);
312315

313316
// Restore `getActionVersion`.
314317
getActionVersionStub.restore();

src/config-utils.ts

Lines changed: 1 addition & 4 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

@@ -1289,7 +1286,7 @@ export function getPathToParsedConfigFile(tempDir: string): string {
12891286
/**
12901287
* Store the given config to the path returned from getPathToParsedConfigFile.
12911288
*/
1292-
async function saveConfig(config: Config, logger: Logger) {
1289+
export async function saveConfig(config: Config, logger: Logger) {
12931290
const configString = JSON.stringify(config);
12941291
const configFile = getPathToParsedConfigFile(config.tempDir);
12951292
fs.mkdirSync(path.dirname(configFile), { recursive: true });

src/init-action.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ async function run() {
680680
} finally {
681681
logUnwrittenDiagnostics();
682682
}
683+
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.
688+
await configUtils.saveConfig(config, logger);
683689
await sendCompletedStatusReport(
684690
startedAt,
685691
config,

0 commit comments

Comments
 (0)