Skip to content

Commit

Permalink
Use hash versions to publish exp packages (#2933)
Browse files Browse the repository at this point in the history
* use sha version instead of semver

* make firebase-exp private

* Publish firebase@exp 0.800.1

* bump umbrella package version only

* Publish firebase@exp 0.800.2

* restore package json

* change prepare to use build:release

* bump version correctly.

* fix function name

* [AUTOMATED]: Prettier Code Styling

* update dep versions

* correct typo

* revert changes for debugging
  • Loading branch information
Feiyang1 authored Apr 20, 2020
1 parent d7c9ed4 commit ed9a7be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages-exp/app-exp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebase/app-exp",
"version": "0.800.0",
"version": "0.0.800",
"private": true,
"description": "FirebaseApp",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
Expand Down Expand Up @@ -29,7 +29,7 @@
"build:doc": "yarn build && yarn doc"
},
"dependencies": {
"@firebase/app-types-exp": "0.800.0",
"@firebase/app-types-exp": "0.0.800",
"@firebase/util": "0.2.44",
"@firebase/logger": "0.2.1",
"@firebase/component": "0.1.9",
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/app-types-exp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebase/app-types-exp",
"version": "0.800.0",
"version": "0.0.800",
"private": true,
"description": "@firebase/app Types",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
Expand Down
5 changes: 3 additions & 2 deletions packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "firebase-exp",
"version": "0.800.0",
"private": true,
"description": "Firebase JavaScript library for web and Node.js",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"license": "Apache-2.0",
Expand Down Expand Up @@ -29,10 +30,10 @@
"build": "rollup -c && gulp firebase-js",
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js",
"dev": "rollup -c -w",
"prepare": "yarn build"
"prepare": "yarn build:release"
},
"dependencies": {
"@firebase/app-exp": "0.800.0"
"@firebase/app-exp": "0.0.800"
},
"devDependencies": {
"rollup": "1.28.0",
Expand Down
39 changes: 31 additions & 8 deletions scripts/exp/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const writeFile = promisify(_writeFile);
const chalk = require('chalk');
const Listr = require('listr');

const FIREBASE_UMBRELLA_PACKAGE_NAME = 'firebase-exp';

async function publishExpPackages() {
try {
/**
Expand All @@ -54,7 +56,7 @@ async function publishExpPackages() {
/**
* It does 2 things:
*
* 1. Bumps the patch version of exp packages regardless if there is any update
* 1. Bumps the patch version of firebase-exp package regardless if there is any update
* since the last release. This simplifies the script and works fine for exp packages.
*
* 2. Removes -exp in package names because we will publish them using
Expand All @@ -69,9 +71,17 @@ async function publishExpPackages() {

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

/**
* push to github
Expand Down Expand Up @@ -112,9 +122,18 @@ async function updatePackageNamesAndVersions(packagePaths) {
const versions = new Map();
for (const path of packagePaths) {
const { version, name } = await readPackageJson(path);
// increase the patch version of all exp packages
const nextVersion = inc(version, 'patch');
versions.set(name, nextVersion);

// increment firebase-exp's patch version
if (name === FIREBASE_UMBRELLA_PACKAGE_NAME) {
const nextVersion = inc(version, 'patch');
versions.set(name, nextVersion);
} else {
// create individual packages version
// we can't use minor version for them because most of them
// are still in the pre-major version officially.
const nextVersion = `${version}-exp.${await getCurrentSha()}`;
versions.set(name, nextVersion);
}
}

await updatePackageJsons(packagePaths, versions, {
Expand Down Expand Up @@ -221,7 +240,7 @@ async function updatePackageJsons(
async function commitAndPush(versions) {
await exec('git add */package.json yarn.lock');

const firebaseExpVersion = versions.get('firebase-exp');
const firebaseExpVersion = versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME);
await exec(
`git commit -m "Publish firebase@exp ${firebaseExpVersion || ''}"`
);
Expand All @@ -237,7 +256,7 @@ async function commitAndPush(versions) {
}

function removeExpInPackageName(name) {
const regex = /^(@firebase.*)-exp(.*)$/g;
const regex = /^(.*firebase.*)-exp(.*)$/g;

const captures = regex.exec(name);
if (!captures) {
Expand All @@ -255,4 +274,8 @@ async function readPackageJson(packagePath) {
return JSON.parse(await readFile(`${packagePath}/package.json`, 'utf8'));
}

async function getCurrentSha() {
return (await git.revparse(['--short', 'HEAD'])).trim();
}

publishExpPackages();

0 comments on commit ed9a7be

Please sign in to comment.