Skip to content

Fix staging workflow #6296

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 17 commits into from
May 25, 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
4 changes: 2 additions & 2 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Set up Node (12)
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 12.x
node-version: 14.x
- name: install Chrome stable
run: |
sudo apt-get update
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/release-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ jobs:
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.OSS_BOT_GITHUB_TOKEN }}
- name: Go back to release branch
# changesets/action created and checked out a new branch
# return to `release` branch.
run: git checkout release
- name: Publish to NPM
# --skipTests No need to run tests
# --skipReinstall Yarn install has already been run
# --ignoreUnstaged Adding the @firebase/app changeset file means
# there's unstaged changes. Ignore.
# TODO: Make these flags defaults in the release script.
run: yarn release --releaseType staging --skipTests --skipReinstall --ignoreUnstaged
run: yarn release --releaseType Staging --ci --skipTests --skipReinstall --ignoreUnstaged
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN_ANALYTICS: ${{secrets.NPM_TOKEN_ANALYTICS}}
NPM_TOKEN_ANALYTICS_INTEROP_TYPES: ${{secrets.NPM_TOKEN_ANALYTICS_INTEROP_TYPES}}
NPM_TOKEN_ANALYTICS_TYPES: ${{secrets.NPM_TOKEN_ANALYTICS_TYPES}}
Expand Down Expand Up @@ -111,11 +116,12 @@ jobs:
VERSION_SCRIPT="const pkg = require('./packages/firebase/package.json'); console.log(pkg.version);"
VERSION=`node -e "${VERSION_SCRIPT}"`
echo "::set-output name=STAGING_VERSION::$VERSION"
BASE_VERSION=$(echo ${{ steps.get-version.outputs.STAGING_VERSION }} | cut -d "-" -f 1)
BASE_VERSION=$(echo $VERSION | cut -d "-" -f 1)
echo "::set-output name=BASE_VERSION::$BASE_VERSION"
- name: Echo version in shell
- name: Echo versions in shell
run: |
echo "Staging release ${{ steps.get-version.outputs.STAGING_VERSION }}"
echo "Base version: ${{ steps.get-version.outputs.BASE_VERSION }}"
- name: Launch E2E tests workflow
# Trigger e2e-test.yml
run: |
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/release.yml

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/release/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ yargs
type: 'boolean',
default: false
},
skipPrompts: {
ci: {
type: 'boolean',
default: false,
desc: 'Skip all interactive prompts (needed if running in CI)'
desc: 'set if running in CI (skips prompts, uses wombot publish)'
}
},
argv => runRelease(argv)
Expand Down
6 changes: 2 additions & 4 deletions scripts/release/prerelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ export async function runPrerelease({
await buildPackages();

/**
* Do not acutally publish if it is a dryrun
* Publish to NPM
*/
if (!dryRun) {
await publishInCI(updates, npmTag);
}
await publishInCI(updates, npmTag, dryRun);
}

const FORBIDDEN_TAGS = ['latest', 'next', 'exp'];
Expand Down
60 changes: 42 additions & 18 deletions scripts/release/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { exec } from 'child-process-promise';
import { createPromptModule } from 'inquirer';
import { publish } from './utils/publish';
import { publish, publishInCI } from './utils/publish';
import { pushReleaseTagsToGithub, cleanTree, hasDiff } from './utils/git';
import {
releaseType as releaseTypePrompt,
Expand All @@ -34,8 +34,8 @@ interface releaseOptions {
skipTests: boolean;
ignoreUnstaged: boolean;
releaseType?: string;
dryRun?: boolean;
skipPrompts: boolean;
dryRun: boolean;
ci: boolean;
}

export async function runRelease({
Expand All @@ -44,8 +44,9 @@ export async function runRelease({
ignoreUnstaged,
releaseType: inputReleaseType,
dryRun,
skipPrompts
ci
}: releaseOptions) {
console.log('ci', ci);
try {
/**
* If there are unstaged changes, error.
Expand Down Expand Up @@ -92,14 +93,16 @@ 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) {
const updatedPackages = await bumpVersionForStaging();

if (!skipPrompts) {
if (!ci) {
// We don't need to validate versions for prod releases because prod releases
// are validated in the version bump PR which should be merged before running this script
const { versionCheck } = await prompt([
Expand All @@ -110,6 +113,10 @@ export async function runRelease({
throw new Error('Version check failed');
}
}

for (const key of updatedPackages.keys()) {
packagesToPublish.push(key);
}
}

/**
Expand Down Expand Up @@ -138,26 +145,43 @@ export async function runRelease({
}

/**
* Do not actually publish if it is a dryrun
* Publish new versions to NPM using changeset (if manual)
* or using wombot for each package (if CI)
* It will also create tags
*/
if (!dryRun) {
if (ci) {
/**
* Release new versions to NPM using changeset
* It will also create tags
* If the script is calling each individual npm command
* it can add the npm flag --dry-run, to better simulate
* everything in the publish process except publishing.
*/
await publish(releaseType);

if (releaseType === ReleaseType.Staging) {
await publishInCI(packagesToPublish, 'next', dryRun);
} else {
// Production.
await publishInCI(packagesToPublish, 'latest', dryRun);
}
} else {
/**
* Changeset creats tags for staging releases as well,
* but we should only push tags to Github for prod releases
* If the script uses changeset to publish, there's no
* way to add the dry-run flag to each npm CLI command.
*/
if (releaseType === ReleaseType.Production) {
/**
* Push release tags created by changeset in publish() to Github
*/
await pushReleaseTagsToGithub();
if (!dryRun) {
// Uses changeset
await publish(releaseType);
}
}

/**
* Changeset creates tags for staging releases as well,
* but we should only push tags to Github for prod releases
*/
if (releaseType === ReleaseType.Production && !dryRun) {
/**
* Push release tags created by changeset in publish() to Github
*/
await pushReleaseTagsToGithub();
}
} catch (err) {
/**
* Log any errors that happened during the process
Expand Down
18 changes: 15 additions & 3 deletions scripts/release/utils/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export async function publish(releaseType: string) {
});
}

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

return {
title: `📦 ${pkg}@${version}`,
task: () => publishPackageInCI(pkg, npmTag)
task: () => publishPackageInCI(pkg, npmTag, dryRun)
};
})
);
Expand All @@ -75,7 +79,11 @@ export async function publishInCI(updatedPkgs: string[], npmTag: string) {
return tasks.run();
}

async function publishPackageInCI(pkg: string, npmTag: string) {
async function publishPackageInCI(
pkg: string,
npmTag: string,
dryRun: boolean
) {
try {
const path = await mapPkgNameToPkgPath(pkg);

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

if (dryRun) {
args.push('--dry-run');
}

// Write proxy registry token for this package to .npmrc.
await exec(
`echo "//wombat-dressing-room.appspot.com/:_authToken=${
Expand Down