Skip to content

Commit d220f34

Browse files
committed
updating staging script
1 parent c0dd7f8 commit d220f34

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

scripts/release/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ yargs
5050
type: 'boolean',
5151
default: false
5252
},
53-
skipPrompts: {
53+
ci: {
5454
type: 'boolean',
5555
default: false,
56-
desc: 'Skip all interactive prompts (needed if running in CI)'
56+
desc: 'set if running in CI (skips prompts, uses wombot publish)'
5757
}
5858
},
5959
argv => runRelease(argv)

scripts/release/release.ts

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { exec } from 'child-process-promise';
1919
import { createPromptModule } from 'inquirer';
20-
import { publish } from './utils/publish';
20+
import { publish, publishInCI } from './utils/publish';
2121
import { pushReleaseTagsToGithub, cleanTree, hasDiff } from './utils/git';
2222
import {
2323
releaseType as releaseTypePrompt,
@@ -27,15 +27,17 @@ import { reinstallDeps, buildPackages } from './utils/yarn';
2727
import { runTests, setupTestDeps } from './utils/tests';
2828
import { bumpVersionForStaging } from './staging';
2929
import { ReleaseType } from './utils/enums';
30+
import { getAllPackages } from './utils/workspace';
31+
import { release } from 'os';
3032
const prompt = createPromptModule();
3133

3234
interface releaseOptions {
3335
skipReinstall: boolean;
3436
skipTests: boolean;
3537
ignoreUnstaged: boolean;
3638
releaseType?: string;
37-
dryRun?: boolean;
38-
skipPrompts: boolean;
39+
dryRun: boolean;
40+
ci: boolean;
3941
}
4042

4143
export async function runRelease({
@@ -44,7 +46,7 @@ export async function runRelease({
4446
ignoreUnstaged,
4547
releaseType: inputReleaseType,
4648
dryRun,
47-
skipPrompts
49+
ci
4850
}: releaseOptions) {
4951
try {
5052
/**
@@ -92,14 +94,16 @@ export async function runRelease({
9294

9395
console.log(`Publishing ${inputReleaseType} release.`);
9496

97+
let packagesToPublish = [];
98+
9599
/**
96100
* Bump versions for staging release
97101
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
98102
*/
99103
if (releaseType === ReleaseType.Staging) {
100104
const updatedPackages = await bumpVersionForStaging();
101105

102-
if (!skipPrompts) {
106+
if (!ci) {
103107
// We don't need to validate versions for prod releases because prod releases
104108
// are validated in the version bump PR which should be merged before running this script
105109
const { versionCheck } = await prompt([
@@ -110,6 +114,10 @@ export async function runRelease({
110114
throw new Error('Version check failed');
111115
}
112116
}
117+
118+
for (const key of updatedPackages.keys()) {
119+
packagesToPublish.push(key);
120+
}
113121
}
114122

115123
/**
@@ -138,26 +146,43 @@ export async function runRelease({
138146
}
139147

140148
/**
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
142152
*/
143-
if (!dryRun) {
153+
if (ci) {
144154
/**
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.
147158
*/
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 {
150166
/**
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.
153169
*/
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);
159173
}
160174
}
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+
}
161186
} catch (err) {
162187
/**
163188
* Log any errors that happened during the process

scripts/release/utils/publish.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function publish(releaseType: string) {
3737
});
3838
}
3939

40-
export async function publishInCI(updatedPkgs: string[], npmTag: string) {
40+
export async function publishInCI(updatedPkgs: string[], npmTag: string, dryRun: boolean) {
4141
const taskArray = await Promise.all(
4242
updatedPkgs.map(async pkg => {
4343
const path = await mapPkgNameToPkgPath(pkg);
@@ -62,7 +62,7 @@ export async function publishInCI(updatedPkgs: string[], npmTag: string) {
6262

6363
return {
6464
title: `📦 ${pkg}@${version}`,
65-
task: () => publishPackageInCI(pkg, npmTag)
65+
task: () => publishPackageInCI(pkg, npmTag, dryRun)
6666
};
6767
})
6868
);
@@ -75,7 +75,7 @@ export async function publishInCI(updatedPkgs: string[], npmTag: string) {
7575
return tasks.run();
7676
}
7777

78-
async function publishPackageInCI(pkg: string, npmTag: string) {
78+
async function publishPackageInCI(pkg: string, npmTag: string, dryRun: boolean) {
7979
try {
8080
const path = await mapPkgNameToPkgPath(pkg);
8181

@@ -92,6 +92,10 @@ async function publishPackageInCI(pkg: string, npmTag: string) {
9292
'https://wombat-dressing-room.appspot.com'
9393
];
9494

95+
if (dryRun) {
96+
args.push('--dry-run');
97+
}
98+
9599
// Write proxy registry token for this package to .npmrc.
96100
await exec(
97101
`echo "//wombat-dressing-room.appspot.com/:_authToken=${

0 commit comments

Comments
 (0)