Skip to content

Prod workflow: Fix logic for detecting published packages #6305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions scripts/release/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { reinstallDeps, buildPackages } from './utils/yarn';
import { runTests, setupTestDeps } from './utils/tests';
import { bumpVersionForStaging } from './staging';
import { ReleaseType } from './utils/enums';
import { getAllPackages } from './utils/workspace';
const prompt = createPromptModule();

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

let packagesToPublish = [];

/**
* Bump versions for staging release
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
*/
if (releaseType === ReleaseType.Staging) {
/**
* Bump versions for staging release
* NOTE: For prod, versions are bumped in a PR which should be merged before running this script
*/
const updatedPackages = await bumpVersionForStaging();

if (!ci) {
Expand All @@ -117,6 +117,13 @@ export async function runRelease({
for (const key of updatedPackages.keys()) {
packagesToPublish.push(key);
}
} else {
/**
* For production releases, pass all packages to publishToCI().
* It will only publish if it finds the local version is newer
* than NPM's.
*/
packagesToPublish = await getAllPackages();
}

/**
Expand Down
74 changes: 39 additions & 35 deletions scripts/release/utils/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,49 @@ export async function publishInCI(
npmTag: string,
dryRun: boolean
) {
const taskArray = await Promise.all(
updatedPkgs.map(async pkg => {
const path = await mapPkgNameToPkgPath(pkg);

/**
* Can't require here because we have a cached version of the required JSON
* in memory and it doesn't contain the updates
*/
const { version, private: isPrivate } = JSON.parse(
await readFile(`${path}/package.json`, 'utf8')
);

/**
* Skip private packages
*/
if (isPrivate) {
return {
title: `Skipping private package: ${pkg}.`,
task: () => {}
};
}
const taskArray = [];
for (const pkg of updatedPkgs) {
const path = await mapPkgNameToPkgPath(pkg);

/**
* Can't require here because we have a cached version of the required JSON
* in memory and it doesn't contain the updates
*/
const { version, private: isPrivate } = JSON.parse(
await readFile(`${path}/package.json`, 'utf8')
);

/**
* Skip if this version has already been published.
*/
const { stdout: npmVersion } = await exec('npm info firebase version');
/**
* Skip private packages
*/
if (isPrivate) {
console.log(`Skipping private package: ${pkg}.`);
continue;
}

/**
* Skip if this version has already been published.
*/
try {
const { stdout: npmVersion } = await exec(`npm info ${pkg} version`);
if (version === npmVersion.trim()) {
return {
title: `Skipping publish of ${pkg} - version ${version} is already published`,
task: () => {}
};
console.log(
`Skipping publish of ${pkg} - version ${version} is already published`
);
continue;
}
} catch (e) {
// 404 from NPM indicates the package doesn't exist there.
console.log(`Skipping pkg: ${pkg} - it has never been published to NPM.`);
continue;
}

taskArray.push({
title: `📦 ${pkg}@${version}`,
task: () => publishPackageInCI(pkg, npmTag, dryRun)
});
}

return {
title: `📦 ${pkg}@${version}`,
task: () => publishPackageInCI(pkg, npmTag, dryRun)
};
})
);
const tasks = new Listr(taskArray, {
concurrent: false,
exitOnError: false
Expand Down