17
17
18
18
import { exec } from 'child-process-promise' ;
19
19
import { createPromptModule } from 'inquirer' ;
20
- import { publish } from './utils/publish' ;
20
+ import { publish , publishInCI } from './utils/publish' ;
21
21
import { pushReleaseTagsToGithub , cleanTree , hasDiff } from './utils/git' ;
22
22
import {
23
23
releaseType as releaseTypePrompt ,
@@ -27,15 +27,17 @@ import { reinstallDeps, buildPackages } from './utils/yarn';
27
27
import { runTests , setupTestDeps } from './utils/tests' ;
28
28
import { bumpVersionForStaging } from './staging' ;
29
29
import { ReleaseType } from './utils/enums' ;
30
+ import { getAllPackages } from './utils/workspace' ;
31
+ import { release } from 'os' ;
30
32
const prompt = createPromptModule ( ) ;
31
33
32
34
interface releaseOptions {
33
35
skipReinstall : boolean ;
34
36
skipTests : boolean ;
35
37
ignoreUnstaged : boolean ;
36
38
releaseType ?: string ;
37
- dryRun ? : boolean ;
38
- skipPrompts : boolean ;
39
+ dryRun : boolean ;
40
+ ci : boolean ;
39
41
}
40
42
41
43
export async function runRelease ( {
@@ -44,7 +46,7 @@ export async function runRelease({
44
46
ignoreUnstaged,
45
47
releaseType : inputReleaseType ,
46
48
dryRun,
47
- skipPrompts
49
+ ci
48
50
} : releaseOptions ) {
49
51
try {
50
52
/**
@@ -92,14 +94,16 @@ export async function runRelease({
92
94
93
95
console . log ( `Publishing ${ inputReleaseType } release.` ) ;
94
96
97
+ let packagesToPublish = [ ] ;
98
+
95
99
/**
96
100
* Bump versions for staging release
97
101
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
98
102
*/
99
103
if ( releaseType === ReleaseType . Staging ) {
100
104
const updatedPackages = await bumpVersionForStaging ( ) ;
101
105
102
- if ( ! skipPrompts ) {
106
+ if ( ! ci ) {
103
107
// We don't need to validate versions for prod releases because prod releases
104
108
// are validated in the version bump PR which should be merged before running this script
105
109
const { versionCheck } = await prompt ( [
@@ -110,6 +114,10 @@ export async function runRelease({
110
114
throw new Error ( 'Version check failed' ) ;
111
115
}
112
116
}
117
+
118
+ for ( const key of updatedPackages . keys ( ) ) {
119
+ packagesToPublish . push ( key ) ;
120
+ }
113
121
}
114
122
115
123
/**
@@ -138,26 +146,43 @@ export async function runRelease({
138
146
}
139
147
140
148
/**
141
- * Do not actually publish if it is a dryrun
149
+ * Publish new versions to NPM using changeset (if manual)
150
+ * or using wombot for each package (if CI)
151
+ * It will also create tags
142
152
*/
143
- if ( ! dryRun ) {
153
+ if ( ci ) {
144
154
/**
145
- * Release new versions to NPM using changeset
146
- * It will also create tags
155
+ * If the script is calling each individual npm command
156
+ * it can add the npm flag --dry-run, to better simulate
157
+ * everything in the publish process except publishing.
147
158
*/
148
- await publish ( releaseType ) ;
149
-
159
+ if ( releaseType === ReleaseType . Staging ) {
160
+ await publishInCI ( packagesToPublish , "next" , dryRun ) ;
161
+ } else {
162
+ // Production.
163
+ await publishInCI ( packagesToPublish , "latest" , dryRun ) ;
164
+ }
165
+ } else {
150
166
/**
151
- * Changeset creats tags for staging releases as well,
152
- * but we should only push tags to Github for prod releases
167
+ * If the script uses changeset to publish, there's no
168
+ * way to add the dry-run flag to each npm CLI command.
153
169
*/
154
- if ( releaseType === ReleaseType . Production ) {
155
- /**
156
- * Push release tags created by changeset in publish() to Github
157
- */
158
- await pushReleaseTagsToGithub ( ) ;
170
+ if ( ! dryRun ) {
171
+ // Uses changeset
172
+ await publish ( releaseType ) ;
159
173
}
160
174
}
175
+
176
+ /**
177
+ * Changeset creates tags for staging releases as well,
178
+ * but we should only push tags to Github for prod releases
179
+ */
180
+ if ( releaseType === ReleaseType . Production && ! dryRun ) {
181
+ /**
182
+ * Push release tags created by changeset in publish() to Github
183
+ */
184
+ await pushReleaseTagsToGithub ( ) ;
185
+ }
161
186
} catch ( err ) {
162
187
/**
163
188
* Log any errors that happened during the process
0 commit comments