Files
renovate/tools/check-git-version.mjs
T
RahulGautamSingh 1d528fc7a2 test: check git version (#11687)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2021-09-15 15:04:17 +00:00

31 lines
858 B
JavaScript

import semver from 'semver';
import shell from 'shelljs';
import simpleGit from 'simple-git';
const GIT_MINIMUM_VERSION = '2.33.0';
const git = simpleGit();
// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
try {
const regex = /\d+\.\d+\.\d+/;
const stdout = await git.raw('--version');
const [gitVersion] = regex.exec(stdout);
if (semver.lt(gitVersion, GIT_MINIMUM_VERSION)) {
if (process.env.CI) {
shell.echo(
`::error ::Minimum Git version ${GIT_MINIMUM_VERSION} is required`
);
} else {
throw new Error(
`Minimum Git version ${GIT_MINIMUM_VERSION} is required`
);
}
}
shell.echo('Found git version: ', gitVersion);
process.exit(0);
} catch (err) {
shell.echo('ERROR:', err.message);
process.exit(1);
}
})();