@@ -25,6 +25,34 @@ import fs from 'mz/fs';
25
25
const root = resolve ( __dirname , '..' ) ;
26
26
const git = simpleGit ( root ) ;
27
27
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
+
28
56
/**
29
57
* Identify modified packages.
30
58
*/
@@ -74,11 +102,12 @@ async function parseChangesetFile(changesetFile: string) {
74
102
const fileText : string = await fs . readFile ( changesetFile , 'utf8' ) ;
75
103
const fileParts = fileText . split ( '---\n' ) ;
76
104
const packageLines = fileParts [ 1 ] . split ( '\n' ) ;
77
- const changesetPackages = packageLines
105
+ const changesetPackages : Record < string , string > = { } ;
106
+ packageLines
78
107
. 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 ( ) ;
82
111
} ) ;
83
112
return changesetPackages ;
84
113
}
@@ -114,13 +143,16 @@ async function main() {
114
143
console . log ( `::set-output name=BLOCKING_FAILURE::true` ) ;
115
144
}
116
145
}
146
+
117
147
try {
118
148
const diffData = await getDiffData ( ) ;
119
149
if ( diffData != null ) {
120
150
const { changedPackages, changesetFile } = diffData ;
121
151
const changesetPackages = await parseChangesetFile ( changesetFile ) ;
152
+
153
+ // Check for packages where files were modified but there's no changeset.
122
154
const missingPackages = [ ...changedPackages ] . filter (
123
- changedPkg => ! changesetPackages . includes ( changedPkg )
155
+ changedPkg => ! Object . keys ( changesetPackages ) . includes ( changedPkg )
124
156
) ;
125
157
if ( missingPackages . length > 0 ) {
126
158
const missingPackagesLines = [
@@ -133,6 +165,26 @@ async function main() {
133
165
missingPackagesLines . push ( ' Make sure this was intentional.' ) ;
134
166
errors . push ( missingPackagesLines . join ( '%0A' ) ) ;
135
167
}
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
+ }
136
188
}
137
189
} catch ( e ) {
138
190
console . error ( chalk `{red ${ e } }` ) ;
0 commit comments