14
14
* This script walks a releaser through bumping the version for a release
15
15
* It will commit the appropriate tags to trigger the CircleCI jobs.
16
16
*/
17
- const { exit} = require ( 'shelljs' ) ;
17
+ const { exit, echo} = require ( 'shelljs' ) ;
18
+ const chalk = require ( 'chalk' ) ;
18
19
const yargs = require ( 'yargs' ) ;
19
20
const inquirer = require ( 'inquirer' ) ;
20
21
const request = require ( 'request' ) ;
22
+ const path = require ( 'path' ) ;
21
23
const { getBranchName, exitIfNotOnGit} = require ( './scm-utils' ) ;
22
24
23
25
const { parseVersion, isReleaseBranch} = require ( './version-utils' ) ;
24
26
const { failIfTagExists} = require ( './release-utils' ) ;
27
+ const checkForGitChanges = require ( './monorepo/check-for-git-changes' ) ;
28
+ const forEachPackage = require ( './monorepo/for-each-package' ) ;
29
+ const detectPackageUnreleasedChanges = require ( './monorepo/bump-all-updated-packages/bump-utils.js' ) ;
30
+
31
+ const ROOT_LOCATION = path . join ( __dirname , '..' ) ;
25
32
26
33
let argv = yargs
27
34
. option ( 'r' , {
@@ -57,6 +64,52 @@ function exitIfNotOnReleaseBranch(branch) {
57
64
}
58
65
}
59
66
67
+ const buildExecutor =
68
+ ( packageAbsolutePath , packageRelativePathFromRoot , packageManifest ) =>
69
+ async ( ) => {
70
+ const { name : packageName } = packageManifest ;
71
+ if ( packageManifest . private ) {
72
+ return ;
73
+ }
74
+
75
+ if (
76
+ detectPackageUnreleasedChanges (
77
+ packageRelativePathFromRoot ,
78
+ packageName ,
79
+ ROOT_LOCATION ,
80
+ )
81
+ ) {
82
+ // if I enter here, I want to throw an error upward
83
+ throw new Error (
84
+ `Package ${ packageName } has unreleased changes. Please release it first.` ,
85
+ ) ;
86
+ }
87
+ } ;
88
+
89
+ const buildAllExecutors = ( ) => {
90
+ const executors = [ ] ;
91
+
92
+ forEachPackage ( ( ...params ) => {
93
+ executors . push ( buildExecutor ( ...params ) ) ;
94
+ } ) ;
95
+
96
+ return executors ;
97
+ } ;
98
+
99
+ async function exitIfUnreleasedPackages ( ) {
100
+ // use the other script to verify that there's no packages in the monorepo
101
+ // that have changes that haven't been released
102
+
103
+ const executors = buildAllExecutors ( ) ;
104
+ for ( const executor of executors ) {
105
+ await executor ( ) . catch ( error => {
106
+ echo ( chalk . red ( error ) ) ;
107
+ // need to throw upward
108
+ throw error ;
109
+ } ) ;
110
+ }
111
+ }
112
+
60
113
function triggerReleaseWorkflow ( options ) {
61
114
return new Promise ( ( resolve , reject ) => {
62
115
request ( options , function ( error , response , body ) {
@@ -74,6 +127,24 @@ async function main() {
74
127
( ) => getBranchName ( ) ,
75
128
"Not in git. You can't invoke bump-oss-versions.js from outside a git repo." ,
76
129
) ;
130
+
131
+ // check for uncommitted changes
132
+ if ( checkForGitChanges ( ) ) {
133
+ echo (
134
+ chalk . red (
135
+ 'Found uncommitted changes. Please commit or stash them before running this script' ,
136
+ ) ,
137
+ ) ;
138
+ exit ( 1 ) ;
139
+ }
140
+
141
+ // now check for unreleased packages
142
+ try {
143
+ await exitIfUnreleasedPackages ( ) ;
144
+ } catch ( error ) {
145
+ exit ( 1 ) ;
146
+ }
147
+
77
148
const token = argv . token ;
78
149
const releaseVersion = argv . toVersion ;
79
150
failIfTagExists ( releaseVersion , 'release' ) ;
0 commit comments