From f19acf15dc06f3ad412cfd6dd56c5fc865d92c7e Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Tue, 20 Jun 2023 19:00:03 +0200 Subject: [PATCH] ci: check that monorepo versions are in sync (#1161) --- .circleci/config.yml | 10 +++++++ package.json | 1 + test/versions/index.js | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100755 test/versions/index.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 45b66214c..a4fff3442 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,6 +118,15 @@ jobs: - run: name: Linting CSS command: yarn run lint:css + test_metadata: + <<: *defaults + steps: + - checkout + - *attach_workspace + - run: *install_yarn_version + - run: + name: Test package versions + command: yarn run test:versions test_types: <<: *defaults steps: @@ -177,6 +186,7 @@ workflows: ci: jobs: - build + - test_metadata - test_lint: requires: - build diff --git a/package.json b/package.json index 1edfccad9..945fd73b4 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "start": "yarn run watch", "test:size": "bundlesize", "test:types": "tsc --noEmit", + "test:versions": "./test/versions/index.js", "test": "jest", "watch": "lerna run watch --parallel --no-private" }, diff --git a/test/versions/index.js b/test/versions/index.js new file mode 100755 index 000000000..dbde83bef --- /dev/null +++ b/test/versions/index.js @@ -0,0 +1,60 @@ +#!/usr/bin/env node +/* eslint-disable no-process-exit, no-console, import/no-commonjs */ +const fs = require('fs'); +const path = require('path'); + +// This file does not use any dependencies, so that it can be ran before installing + +// It checks whether the versions of packages that should be versioned synchronously +// are actually in sync. We need this as long as Lerna doesn't have a mixed mode. +// see: https://github.com/lerna/lerna/issues/1159 + +let hasError = false; +const expectedVersion = require('../../lerna.json').version; +const packages = fs.readdirSync(path.join(__dirname, '../../packages')); + +const results = packages.map((package) => { + const version = require(path.join( + __dirname, + `../../packages/${package}/package.json` + )).version; + return { isValid: version === expectedVersion, package, version }; +}); + +if (results.some(({ isValid }) => !isValid)) { + console.error( + [ + 'Package version mismatch detected!', + `- Expected: ${expectedVersion}`, + '- Received:', + ].join('\n') + ); + console.error(results.filter(({ isValid }) => !isValid)); + hasError = true; +} else { + console.log('Package versions are in sync.'); +} + +console.log(''); + +const sharedVersion = fs.readFileSync( + path.join(__dirname, '../../packages/autocomplete-shared/src/version.ts'), + { encoding: 'utf-8' } +); + +if (sharedVersion !== `export const version = '${expectedVersion}';\n`) { + console.error( + [ + 'Shared version mismatch detected!', + `- Expected: ${expectedVersion}`, + `- Received: ${sharedVersion}`, + ].join('\n') + ); + hasError = true; +} else { + console.log('Shared version file is in sync.'); +} + +if (hasError) { + process.exit(1); +}