@@ -25,6 +25,34 @@ import fs from 'mz/fs';
2525const root = resolve ( __dirname , '..' ) ;
2626const 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, bump text, package name.
38+ */
39+ function getHighestBump ( changesetPackages : Record < string , string > ) {
40+ let highestBump = bumpRank . patch ;
41+ let highestBumpText = 'patch' ;
42+ let bumpPackage = '' ;
43+ for ( const pkgName of Object . keys ( changesetPackages ) ) {
44+ if (
45+ pkgName !== 'firebase' &&
46+ bumpRank [ changesetPackages [ pkgName ] ] > highestBump
47+ ) {
48+ highestBump = bumpRank [ changesetPackages [ pkgName ] ] ;
49+ highestBumpText = changesetPackages [ pkgName ] ;
50+ bumpPackage = pkgName ;
51+ }
52+ }
53+ return { highestBump, bumpText : highestBumpText , bumpPackage } ;
54+ }
55+
2856/**
2957 * Identify modified packages.
3058 */
@@ -74,11 +102,12 @@ async function parseChangesetFile(changesetFile: string) {
74102 const fileText : string = await fs . readFile ( changesetFile , 'utf8' ) ;
75103 const fileParts = fileText . split ( '---\n' ) ;
76104 const packageLines = fileParts [ 1 ] . split ( '\n' ) ;
77- const changesetPackages = packageLines
105+ const changesetPackages : Record < string , string > = { } ;
106+ packageLines
78107 . filter ( line => line )
79- . map ( line => {
80- const [ packageName ] = line . split ( ':' ) ;
81- return packageName . replace ( / [ ' " ] / g, '' ) ;
108+ . forEach ( line => {
109+ const [ packageName , bumpType ] = line . split ( ':' ) ;
110+ changesetPackages [ packageName . replace ( / [ ' " ] / g, '' ) ] = bumpType . trim ( ) ;
82111 } ) ;
83112 return changesetPackages ;
84113}
@@ -114,13 +143,16 @@ async function main() {
114143 console . log ( `::set-output name=BLOCKING_FAILURE::true` ) ;
115144 }
116145 }
146+
117147 try {
118148 const diffData = await getDiffData ( ) ;
119149 if ( diffData != null ) {
120150 const { changedPackages, changesetFile } = diffData ;
121151 const changesetPackages = await parseChangesetFile ( changesetFile ) ;
152+
153+ // Check for packages where files were modified but there's no changeset.
122154 const missingPackages = [ ...changedPackages ] . filter (
123- changedPkg => ! changesetPackages . includes ( changedPkg )
155+ changedPkg => ! Object . keys ( changesetPackages ) . includes ( changedPkg )
124156 ) ;
125157 if ( missingPackages . length > 0 ) {
126158 const missingPackagesLines = [
@@ -133,6 +165,26 @@ async function main() {
133165 missingPackagesLines . push ( ' Make sure this was intentional.' ) ;
134166 errors . push ( missingPackagesLines . join ( '%0A' ) ) ;
135167 }
168+
169+ // Check for packages with a minor or major bump where 'firebase' hasn't been
170+ // bumped high enough or at all.
171+ const { highestBump, bumpText, bumpPackage } = getHighestBump (
172+ changesetPackages
173+ ) ;
174+ if ( highestBump > bumpRank . patch ) {
175+ if ( changesetPackages [ 'firebase' ] == null ) {
176+ errors . push (
177+ `- Package ${ bumpPackage } has a ${ bumpText } bump which requires an ` +
178+ `additional line to bump the main "firebase" package to ${ bumpText } .`
179+ ) ;
180+ } else if ( bumpRank [ changesetPackages [ 'firebase' ] ] < highestBump ) {
181+ errors . push (
182+ `- Package ${ bumpPackage } has a ${ bumpText } bump. ` +
183+ `Increase the bump for the main "firebase" package to ${ bumpText } .`
184+ ) ;
185+ }
186+ console . log ( `::set-output name=BLOCKING_FAILURE::true` ) ;
187+ }
136188 }
137189 } catch ( e ) {
138190 console . error ( chalk `{red ${ e } }` ) ;
0 commit comments