Skip to content

Commit

Permalink
test: check git version (#11687)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Sep 15, 2021
1 parent b9ae26b commit 1d528fc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build-pr.yml
Expand Up @@ -100,6 +100,7 @@ jobs:
yarn eslint -f gha
yarn prettier
yarn markdown-lint
yarn git-check
- name: Test schema
run: yarn test-schema
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Expand Up @@ -134,6 +134,7 @@ jobs:
yarn eslint -f gha
yarn prettier
yarn markdown-lint
yarn git-check
- name: Test schema
run: yarn test-schema
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -19,10 +19,11 @@
"eslint-fix": "eslint --ext .js,.mjs,.ts --fix lib/ test/ tools/",
"generate": "run-s generate:*",
"generate:imports": "node tools/generate-imports.mjs",
"git-check": "node tools/check-git-version.mjs",
"jest": "cross-env NODE_ENV=test LOG_LEVEL=fatal node --expose-gc node_modules/jest/bin/jest.js --logHeapUsage",
"jest-debug": "cross-env NODE_OPTIONS=--inspect-brk yarn jest",
"jest-silent": "cross-env yarn jest --reporters jest-silent-reporter",
"lint": "run-s ls-lint eslint prettier markdown-lint",
"lint": "run-s ls-lint eslint prettier markdown-lint git-check",
"lint-fix": "run-s eslint-fix prettier-fix markdown-lint-fix",
"ls-lint": "ls-lint",
"markdown-lint": "markdownlint-cli2",
Expand Down
30 changes: 30 additions & 0 deletions tools/check-git-version.mjs
@@ -0,0 +1,30 @@
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);
}
})();

0 comments on commit 1d528fc

Please sign in to comment.