Skip to content

Commit f19acf1

Browse files
authored
ci: check that monorepo versions are in sync (#1161)
1 parent 498d34e commit f19acf1

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ jobs:
118118
- run:
119119
name: Linting CSS
120120
command: yarn run lint:css
121+
test_metadata:
122+
<<: *defaults
123+
steps:
124+
- checkout
125+
- *attach_workspace
126+
- run: *install_yarn_version
127+
- run:
128+
name: Test package versions
129+
command: yarn run test:versions
121130
test_types:
122131
<<: *defaults
123132
steps:
@@ -177,6 +186,7 @@ workflows:
177186
ci:
178187
jobs:
179188
- build
189+
- test_metadata
180190
- test_lint:
181191
requires:
182192
- build

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"start": "yarn run watch",
2222
"test:size": "bundlesize",
2323
"test:types": "tsc --noEmit",
24+
"test:versions": "./test/versions/index.js",
2425
"test": "jest",
2526
"watch": "lerna run watch --parallel --no-private"
2627
},

test/versions/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-process-exit, no-console, import/no-commonjs */
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// This file does not use any dependencies, so that it can be ran before installing
7+
8+
// It checks whether the versions of packages that should be versioned synchronously
9+
// are actually in sync. We need this as long as Lerna doesn't have a mixed mode.
10+
// see: https://github.com/lerna/lerna/issues/1159
11+
12+
let hasError = false;
13+
const expectedVersion = require('../../lerna.json').version;
14+
const packages = fs.readdirSync(path.join(__dirname, '../../packages'));
15+
16+
const results = packages.map((package) => {
17+
const version = require(path.join(
18+
__dirname,
19+
`../../packages/${package}/package.json`
20+
)).version;
21+
return { isValid: version === expectedVersion, package, version };
22+
});
23+
24+
if (results.some(({ isValid }) => !isValid)) {
25+
console.error(
26+
[
27+
'Package version mismatch detected!',
28+
`- Expected: ${expectedVersion}`,
29+
'- Received:',
30+
].join('\n')
31+
);
32+
console.error(results.filter(({ isValid }) => !isValid));
33+
hasError = true;
34+
} else {
35+
console.log('Package versions are in sync.');
36+
}
37+
38+
console.log('');
39+
40+
const sharedVersion = fs.readFileSync(
41+
path.join(__dirname, '../../packages/autocomplete-shared/src/version.ts'),
42+
{ encoding: 'utf-8' }
43+
);
44+
45+
if (sharedVersion !== `export const version = '${expectedVersion}';\n`) {
46+
console.error(
47+
[
48+
'Shared version mismatch detected!',
49+
`- Expected: ${expectedVersion}`,
50+
`- Received: ${sharedVersion}`,
51+
].join('\n')
52+
);
53+
hasError = true;
54+
} else {
55+
console.log('Shared version file is in sync.');
56+
}
57+
58+
if (hasError) {
59+
process.exit(1);
60+
}

0 commit comments

Comments
 (0)