Skip to content

Commit 487c467

Browse files
committed
Modify script
1 parent 6766da2 commit 487c467

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

scripts/check_changeset.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ import fs from 'mz/fs';
2525
const root = resolve(__dirname, '..');
2626
const git = simpleGit(root);
2727

28+
// Version bump text converted to rankable numbers.
29+
const bumpRank: Record<string, number> = {
30+
'patch': 0,
31+
'minor': 1,
32+
'major': 2
33+
};
34+
35+
/**
36+
* Get highest bump that isn't the main firebase package, return
37+
// numerical rank and bump text.
38+
*/
39+
function getHighestBump(changesetPackages: Record<string, string>) {
40+
let highestBump = bumpRank.patch;
41+
let highestBumpText = 'patch';
42+
for (const pkgName in changesetPackages) {
43+
if (
44+
pkgName !== 'firebase' &&
45+
bumpRank[changesetPackages[pkgName]] > highestBump
46+
) {
47+
highestBump = bumpRank[changesetPackages[pkgName]];
48+
highestBumpText = changesetPackages[pkgName];
49+
}
50+
}
51+
return { highestBump, bumpText: highestBumpText };
52+
}
53+
2854
/**
2955
* Identify modified packages.
3056
*/
@@ -74,11 +100,12 @@ async function parseChangesetFile(changesetFile: string) {
74100
const fileText: string = await fs.readFile(changesetFile, 'utf8');
75101
const fileParts = fileText.split('---\n');
76102
const packageLines = fileParts[1].split('\n');
77-
const changesetPackages = packageLines
103+
const changesetPackages: Record<string, string> = {};
104+
packageLines
78105
.filter(line => line)
79-
.map(line => {
80-
const [packageName] = line.split(':');
81-
return packageName.replace(/['"]/g, '');
106+
.forEach(line => {
107+
const [packageName, bumpType] = line.split(':');
108+
changesetPackages[packageName.replace(/['"]/g, '')] = bumpType.trim();
82109
});
83110
return changesetPackages;
84111
}
@@ -114,13 +141,16 @@ async function main() {
114141
console.log(`::set-output name=BLOCKING_FAILURE::true`);
115142
}
116143
}
144+
117145
try {
118146
const diffData = await getDiffData();
119147
if (diffData != null) {
120148
const { changedPackages, changesetFile } = diffData;
121149
const changesetPackages = await parseChangesetFile(changesetFile);
150+
151+
// Check for packages where files were modified but there's no changeset.
122152
const missingPackages = [...changedPackages].filter(
123-
changedPkg => !changesetPackages.includes(changedPkg)
153+
changedPkg => !Object.keys(changesetPackages).includes(changedPkg)
124154
);
125155
if (missingPackages.length > 0) {
126156
const missingPackagesLines = [
@@ -133,6 +163,24 @@ async function main() {
133163
missingPackagesLines.push(' Make sure this was intentional.');
134164
errors.push(missingPackagesLines.join('%0A'));
135165
}
166+
167+
// Check for packages with a minor or major bump where 'firebase' hasn't been
168+
// included.
169+
const { highestBump, bumpText } = getHighestBump(changesetPackages);
170+
if (highestBump > bumpRank.patch) {
171+
if (changesetPackages['firebase'] == null) {
172+
errors.push(
173+
`- There is a package with a ${bumpText} bump which requires an ` +
174+
`additional line to bump the main "firebase" package to ${bumpText}.`
175+
);
176+
} else if (bumpRank[changesetPackages['firebase']] < highestBump) {
177+
errors.push(
178+
`- There is a package with a ${bumpText} bump. ` +
179+
`Increase the bump for the main "firebase" package to ${bumpText}.`
180+
);
181+
}
182+
console.log(`::set-output name=BLOCKING_FAILURE::true`);
183+
}
136184
}
137185
} catch (e) {
138186
console.error(chalk`{red ${e}}`);

0 commit comments

Comments
 (0)