renovate/tools/check-git-version.mjs
RahulGautamSingh 54b36695a7
refactor: simplify git version check (#17763)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-09-14 13:47:33 +02:00

29 lines
873 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();
await (async () => {
try {
const { major, minor, patch, installed } = await git.version();
const gitVersion = `${major}.${minor}.${patch}`;
if (!installed || semver.lt(gitVersion, GIT_MINIMUM_VERSION)) {
if (process.env.CI) {
shell.echo(
`::error ::Minimum Git version ${GIT_MINIMUM_VERSION} is required, found version '${gitVersion}'.`
);
} else {
throw new Error(
`Minimum Git version ${GIT_MINIMUM_VERSION} is required, found version '${gitVersion}'.`
);
}
}
shell.echo('Found git version: ', gitVersion);
process.exit(0);
} catch (err) {
shell.echo('ERROR:', err.message);
process.exit(1);
}
})();