Skip to content

Commit

Permalink
ci: check that monorepo versions are in sync (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab authored Jun 20, 2023
1 parent 498d34e commit f19acf1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -177,6 +186,7 @@ workflows:
ci:
jobs:
- build
- test_metadata
- test_lint:
requires:
- build
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
60 changes: 60 additions & 0 deletions test/versions/index.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit f19acf1

Please sign in to comment.