Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): detect missing RENOVATE_CONFIG_FILE #13196

Merged
merged 9 commits into from
Dec 22, 2021
29 changes: 25 additions & 4 deletions lib/workers/global/config/parse/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ describe('workers/global/config/parse/file', () => {
expect(res.rangeStrategy).toBe('bump');
});

it('parse and returns empty config if there is no RENOVATE_CONFIG_FILE in env', async () => {
expect(await file.getConfig({})).toBeDefined();
});

it.each([
[
'config.js',
Expand Down Expand Up @@ -92,6 +88,31 @@ describe('workers/global/config/parse/file', () => {
expect(mockProcessExit).toHaveBeenCalledWith(1);
});

it('fatal error and exit if config.js contains unresolved env var', async () => {
const mockProcessExit = jest
.spyOn(process, 'exit')
.mockImplementation(() => undefined as never);

const configFile = upath.resolve(
__dirname,
'./__fixtures__/config-ref-error.js-invalid'
);
const tmpDir = tmp.path;
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
}
const tmpConfigFile = upath.resolve(tmpDir, 'config-ref-error.js');
console.log(tmpConfigFile);
fs.copyFileSync(configFile, tmpConfigFile);

await file.getConfig({ RENOVATE_CONFIG_FILE: tmpConfigFile });

expect(logger.fatal).toHaveBeenCalledWith(
`Config file parsing error: CI_API_V4_URL is not defined`
);
expect(mockProcessExit).toHaveBeenCalledWith(1);
});

it.each([
['invalid config file type', './file.txt'],
['missing config file type', './file'],
Expand Down
6 changes: 6 additions & 0 deletions lib/workers/global/config/parse/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export async function getConfig(env: NodeJS.ProcessEnv): Promise<AllConfig> {
if (err instanceof SyntaxError || err instanceof TypeError) {
logger.fatal(`Could not parse config file \n ${err.stack}`);
process.exit(1);
} else if (err instanceof ReferenceError) {
logger.fatal(`Config file parsing error: ${err.message}`);
process.exit(1);
} else if (err.code === 'MODULE_NOT_FOUND') {
logger.fatal(`Config file ${configFile} must present`);
process.exit(1);
} else if (err.message === 'Unsupported file type') {
logger.fatal(err.message);
process.exit(1);
Expand Down