From 1d528fc7a24e4ac77f347b3ead7cd209a17f4738 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 15 Sep 2021 20:49:17 +0545 Subject: [PATCH] test: check git version (#11687) Co-authored-by: Rhys Arkins Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: Michael Kriese --- .github/workflows/build-pr.yml | 1 + .github/workflows/build.yml | 1 + package.json | 3 ++- tools/check-git-version.mjs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tools/check-git-version.mjs diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 299350a8755aac..09798362d1ceee 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -100,6 +100,7 @@ jobs: yarn eslint -f gha yarn prettier yarn markdown-lint + yarn git-check - name: Test schema run: yarn test-schema diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 303eb15be19c6a..e04f05b571da25 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -134,6 +134,7 @@ jobs: yarn eslint -f gha yarn prettier yarn markdown-lint + yarn git-check - name: Test schema run: yarn test-schema diff --git a/package.json b/package.json index 43abc8de1cf680..f5ccba9a341817 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tools/check-git-version.mjs b/tools/check-git-version.mjs new file mode 100644 index 00000000000000..65b006acbefd85 --- /dev/null +++ b/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); + } +})();