Skip to content

Fix issues in the exp release script #4293

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 11 commits into from
Jan 15, 2021
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"stage:packages": "./scripts/prepublish.sh",
"repl": "node tools/repl.js",
"release": "ts-node-script scripts/release/cli.ts",
"release:exp": "ts-node-script scripts/exp/release.ts",
"pretest": "node tools/pretest.js",
"test": "lerna run --concurrency 4 --stream test",
"test:ci": "lerna run --concurrency 4 test:ci",
Expand Down
1 change: 1 addition & 0 deletions packages-exp/messaging-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c && yarn api-report",
"build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build",
"build:release": "rollup -c rollup.config.release.js && yarn api-report",
"dev": "rollup -c -w",
"test": "run-p test:karma type-check lint ",
"test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test",
Expand Down
20 changes: 0 additions & 20 deletions scripts/exp/prepare-firestore-for-exp-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,4 @@ export async function prepare() {
`${JSON.stringify(packageJson, null, 2)}\n`,
{ encoding: 'utf-8' }
);

const expTypingPath = `${packagePath}/${packageJson.typings}`;
const liteTypingPath = path.resolve(
`${packagePath}/lite`,
litePackageJson.typings
);

// remove -exp in typings files
await replaceAppTypesExpInFile(expTypingPath);
await replaceAppTypesExpInFile(liteTypingPath);
}

async function replaceAppTypesExpInFile(filePath: string): Promise<void> {
const fileContent = await readFile(filePath, { encoding: 'utf-8' });
const newFileContent = fileContent.replace(
'@firebase/app-types-exp',
'@firebase/app-types'
);

await writeFile(filePath, newFileContent, { encoding: 'utf-8' });
}
105 changes: 82 additions & 23 deletions scripts/exp/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@

import { spawn, exec } from 'child-process-promise';
import ora from 'ora';
import { createPromptModule } from 'inquirer';
import { projectRoot, readPackageJson } from '../utils';
import simpleGit from 'simple-git/promise';

import { mapWorkspaceToPackages } from '../release/utils/workspace';
import { inc } from 'semver';
import { writeFile as _writeFile } from 'fs';
import { writeFile as _writeFile, rmdirSync, existsSync } from 'fs';
import { resolve } from 'path';
import { promisify } from 'util';
import chalk from 'chalk';
import Listr from 'listr';
import { prepare as prepareFirestoreForRelease } from './prepare-firestore-for-exp-release';
import * as yargs from 'yargs';

const prompt = createPromptModule();
const argv = yargs
.options({
dryRun: {
Expand Down Expand Up @@ -79,36 +82,79 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) {
*/
const versions = await updatePackageNamesAndVersions(packagePaths);

let versionCheckMessage =
'\r\nAre you sure these are the versions you want to publish?\r\n';
for (const [pkgName, version] of versions) {
versionCheckMessage += `${pkgName} : ${version}\n`;
}
const { versionCheck } = await prompt([
{
type: 'confirm',
name: 'versionCheck',
message: versionCheckMessage,
default: false
}
]);

if (!versionCheck) {
throw new Error('Version check failed');
}

/**
* Do not publish to npm and create tags if it's a dryrun
* Release packages to NPM
*/
if (!dryRun) {
/**
* Release packages to NPM
*/
await publishToNpm(packagePaths);
await publishToNpm(packagePaths, dryRun);

/**
* reset the working tree to recover package names with -exp in the package.json files,
* then bump patch version of firebase-exp (the umbrella package) only
*/
const firebaseExpVersion = new Map<string, string>();
firebaseExpVersion.set(
FIREBASE_UMBRELLA_PACKAGE_NAME,
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
);
const firebaseExpPath = packagePaths.filter(p =>
p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME)
);
/**
* reset the working tree to recover package names with -exp in the package.json files,
* then bump patch version of firebase-exp (the umbrella package) only
*/
const firebaseExpVersion = new Map<string, string>();
firebaseExpVersion.set(
FIREBASE_UMBRELLA_PACKAGE_NAME,
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
);
const firebaseExpPath = packagePaths.filter(p =>
p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME)
);

const { resetWorkingTree } = await prompt([
{
type: 'confirm',
name: 'resetWorkingTree',
message: 'Do you want to reset the working tree?',
default: true
}
]);

if (resetWorkingTree) {
await resetWorkingTreeAndBumpVersions(
firebaseExpPath,
firebaseExpVersion
);
} else {
process.exit(0);
}

/**
* Do not push to remote if it's a dryrun
*/
if (!dryRun) {
const { commitAndPush } = await prompt([
{
type: 'confirm',
name: 'commitAndPush',
message:
'Do you want to commit and push the exp version update to remote?',
default: true
}
]);
/**
* push to github
*/
await commitAndPush(versions);
if (commitAndPush) {
await commitAndPush(versions);
}
}
} catch (err) {
/**
Expand Down Expand Up @@ -199,6 +245,16 @@ async function buildPackages() {
}
);

// remove packages/installations/dist, otherwise packages that depend on packages-exp/installations-exp (e.g. Perf, FCM)
// will incorrectly reference packages/installations.
const installationsDistDirPath = resolve(
projectRoot,
'packages/installations/dist'
);
if (existsSync(installationsDistDirPath)) {
rmdirSync(installationsDistDirPath, { recursive: true });
}

// Build firebase-exp
await spawn(
'yarn',
Expand Down Expand Up @@ -242,13 +298,13 @@ async function updatePackageNamesAndVersions(packagePaths: string[]) {
return versions;
}

async function publishToNpm(packagePaths: string[]) {
async function publishToNpm(packagePaths: string[], dryRun = false) {
const taskArray = await Promise.all(
packagePaths.map(async pp => {
const { version, name } = await readPackageJson(pp);
return {
title: `📦 ${name}@${version}`,
task: () => publishPackage(pp)
task: () => publishPackage(pp, dryRun)
};
})
);
Expand All @@ -262,8 +318,11 @@ async function publishToNpm(packagePaths: string[]) {
return tasks.run();
}

async function publishPackage(packagePath: string) {
async function publishPackage(packagePath: string, dryRun: boolean) {
const args = ['publish', '--access', 'public', '--tag', 'exp'];
if (dryRun) {
args.push('--dry-run');
}
await spawn('npm', args, { cwd: packagePath });
}

Expand Down