mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
fix: try/catch dockerfile replace (#1022)
This commit is contained in:
parent
826753e329
commit
a65a149b8d
2 changed files with 26 additions and 7 deletions
|
@ -9,11 +9,16 @@ function setNewValue(
|
||||||
newVersion,
|
newVersion,
|
||||||
logger
|
logger
|
||||||
) {
|
) {
|
||||||
logger.debug(`setNewValue: ${depName} = ${newVersion}`);
|
try {
|
||||||
const regexReplace = new RegExp(`(^|\n)FROM ${currentVersion}\n`);
|
logger.debug(`setNewValue: ${depName} = ${newVersion}`);
|
||||||
const newFileContent = currentFileContent.replace(
|
const regexReplace = new RegExp(`(^|\n)FROM ${currentVersion}\n`);
|
||||||
regexReplace,
|
const newFileContent = currentFileContent.replace(
|
||||||
`$1FROM ${newVersion}\n`
|
regexReplace,
|
||||||
);
|
`$1FROM ${newVersion}\n`
|
||||||
return newFileContent;
|
);
|
||||||
|
return newFileContent;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({ err }, 'Error setting new Dockerfile value');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,19 @@ describe('workers/branch/dockerfile', () => {
|
||||||
);
|
);
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
it('returns null on error', () => {
|
||||||
|
const currentFileContent = null;
|
||||||
|
const depName = 'node';
|
||||||
|
const currentVersion = 'node:8';
|
||||||
|
const newVersion = 'node:8@sha256:abcdefghijklmnop';
|
||||||
|
const res = dockerfile.setNewValue(
|
||||||
|
currentFileContent,
|
||||||
|
depName,
|
||||||
|
currentVersion,
|
||||||
|
newVersion,
|
||||||
|
logger
|
||||||
|
);
|
||||||
|
expect(res).toBe(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue