Skip to content

Commit cadc804

Browse files
authored
Prod workflow: Fix logic for detecting published packages (#6305)
1 parent 8d03c8a commit cadc804

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

scripts/release/release.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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';
3031
const prompt = createPromptModule();
3132

3233
interface releaseOptions {
@@ -94,12 +95,11 @@ export async function runRelease({
9495
console.log(`Publishing ${inputReleaseType} release.`);
9596

9697
let packagesToPublish = [];
97-
98-
/**
99-
* Bump versions for staging release
100-
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
101-
*/
10298
if (releaseType === ReleaseType.Staging) {
99+
/**
100+
* Bump versions for staging release
101+
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
102+
*/
103103
const updatedPackages = await bumpVersionForStaging();
104104

105105
if (!ci) {
@@ -117,6 +117,13 @@ export async function runRelease({
117117
for (const key of updatedPackages.keys()) {
118118
packagesToPublish.push(key);
119119
}
120+
} else {
121+
/**
122+
* For production releases, pass all packages to publishToCI().
123+
* It will only publish if it finds the local version is newer
124+
* than NPM's.
125+
*/
126+
packagesToPublish = await getAllPackages();
120127
}
121128

122129
/**

scripts/release/utils/publish.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,49 @@ export async function publishInCI(
4242
npmTag: string,
4343
dryRun: boolean
4444
) {
45-
const taskArray = await Promise.all(
46-
updatedPkgs.map(async pkg => {
47-
const path = await mapPkgNameToPkgPath(pkg);
48-
49-
/**
50-
* Can't require here because we have a cached version of the required JSON
51-
* in memory and it doesn't contain the updates
52-
*/
53-
const { version, private: isPrivate } = JSON.parse(
54-
await readFile(`${path}/package.json`, 'utf8')
55-
);
56-
57-
/**
58-
* Skip private packages
59-
*/
60-
if (isPrivate) {
61-
return {
62-
title: `Skipping private package: ${pkg}.`,
63-
task: () => {}
64-
};
65-
}
45+
const taskArray = [];
46+
for (const pkg of updatedPkgs) {
47+
const path = await mapPkgNameToPkgPath(pkg);
48+
49+
/**
50+
* Can't require here because we have a cached version of the required JSON
51+
* in memory and it doesn't contain the updates
52+
*/
53+
const { version, private: isPrivate } = JSON.parse(
54+
await readFile(`${path}/package.json`, 'utf8')
55+
);
6656

67-
/**
68-
* Skip if this version has already been published.
69-
*/
70-
const { stdout: npmVersion } = await exec('npm info firebase version');
57+
/**
58+
* Skip private packages
59+
*/
60+
if (isPrivate) {
61+
console.log(`Skipping private package: ${pkg}.`);
62+
continue;
63+
}
64+
65+
/**
66+
* Skip if this version has already been published.
67+
*/
68+
try {
69+
const { stdout: npmVersion } = await exec(`npm info ${pkg} version`);
7170
if (version === npmVersion.trim()) {
72-
return {
73-
title: `Skipping publish of ${pkg} - version ${version} is already published`,
74-
task: () => {}
75-
};
71+
console.log(
72+
`Skipping publish of ${pkg} - version ${version} is already published`
73+
);
74+
continue;
7675
}
76+
} catch (e) {
77+
// 404 from NPM indicates the package doesn't exist there.
78+
console.log(`Skipping pkg: ${pkg} - it has never been published to NPM.`);
79+
continue;
80+
}
81+
82+
taskArray.push({
83+
title: `📦 ${pkg}@${version}`,
84+
task: () => publishPackageInCI(pkg, npmTag, dryRun)
85+
});
86+
}
7787

78-
return {
79-
title: `📦 ${pkg}@${version}`,
80-
task: () => publishPackageInCI(pkg, npmTag, dryRun)
81-
};
82-
})
83-
);
8488
const tasks = new Listr(taskArray, {
8589
concurrent: false,
8690
exitOnError: false

0 commit comments

Comments
 (0)