Skip to content
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

misc: add releasing scripts #8387

Merged
merged 5 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
86 changes: 16 additions & 70 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,20 @@ We follow [semver](https://semver.org/) versioning semantics (`vMajor.Minor.Patc
## Release Process

```sh
# use a custom lighthouse-pristine checkout to make sure your dev files aren't involved.

# * Install the latest.*
yarn

# * Bump it *
yarn version --no-git-tag-version
# manually bump extension v in clients/extension/manifest.json
yarn update:sample-json

# * Build it. This also builds the cli, extension, and viewer. *
yarn build-all

# * Test err'thing *
echo "Test the CLI."
yarn start "https://example.com" --view
yarn smoke

echo "Test the extension"
# ...

echo "Test a fresh local install"
# (starting from lighthouse-pristine root...)
npm pack
cd ..; rm -rf tmp; mkdir tmp; cd tmp
npm init -y
npm install ../lighthouse-pristine/lighthouse-*.tgz
npm explore lighthouse -- npm run smoke
npm explore lighthouse -- npm run chrome # try the manual launcher
npm explore lighthouse -- npm run fast -- http://example.com
cd ..; rm -rf ./tmp;

cd ../lighthouse-pristine; command rm -f lighthouse-*.tgz

echo "Test the lighthouse-viewer build"
# Manual test for now:
# Start a server in dist/viewer/ and open the page in a tab. You should see the viewer.
# Drop in a results.json or paste an existing gist url (e.g. https://gist.github.com/ebidel/b9fd478b5f40bf5fab174439dc18f83a).
# Check for errors!
cd dist/viewer ; python -m SimpleHTTPServer
# go to http://localhost:8000/

# * Update changelog *
git fetch --tags
yarn changelog
# add new contributors, e.g. from git shortlog -s -e -n v2.3.0..HEAD
# and https://github.com/GoogleChrome/lighthouse/graphs/contributors
echo "Edit the changelog for readability and brevity"

# * Put up the PR *
echo "Branch and commit the version bump."
git checkout -b bumpv240
git commit -am "2.4.0"
echo "Generate a PR and get it merged."

echo "Once it's merged, pull master and tag the (squashed) commit"
git tag -a v2.4.0 -m "v2.4.0"
git push --tags


# * Deploy-time *
echo "Rebuild extension and viewer to get the latest, tagged master commit"
yarn build-all;

# zip the extension files
# Run the tests
bash ./lighthouse-core/scripts/publish-test.sh
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
# Prepare the commit
bash ./lighthouse-core/scripts/publish-prepare-commit.sh

# Open the PR and await merge...
echo "It's been merged! 🎉"

# Run the tests again :)
bash ./lighthouse-core/scripts/publish-test.sh
# Package everything for publishing
bash ./lighthouse-core/scripts/publish-prepare-package.sh

# Upload the extension
node build/build-extension.js package; cd dist/extension-package/
echo "Go here: https://chrome.google.com/webstore/developer/edit/blipmdconlkpinefehnmjammfjpmpbjk "
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
echo "Upload the package zip to CWS dev dashboard"
Expand All @@ -106,12 +55,9 @@ echo "Upload the package zip to CWS dev dashboard"
# Select `lighthouse-4.X.X.zip`
# _Publish_ at the bottom

echo "Verify the npm package won't include unncessary files"
npm pack --dry-run
npx pkgfiles

echo "ship it"
# Publish to NPM
npm publish
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
# Publish viewer
yarn deploy-viewer

# * Tell the world!!! *
Expand Down
17 changes: 17 additions & 0 deletions lighthouse-core/scripts/publish-clean-pristine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_ROOT="$DIRNAME/../.."
cd $LH_ROOT

set -euxo pipefail

# Setup a pristine git environment
cd ../lighthouse-pristine

if [[ -z "$(git status --porcelain)" ]]; then
echo "Pristine repo already clean!"
exit 0
fi

git clean -fx
75 changes: 75 additions & 0 deletions lighthouse-core/scripts/publish-prepare-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

TXT_BOLD=$(tput bold)
TXT_DIM=$(tput setaf 245)
TXT_RESET=$(tput sgr0)

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_ROOT="$DIRNAME/../.."
cd "$LH_ROOT"

set -euxo pipefail

if [[ "$#" -ne 1 ]]; then
echo "You must specify the version to prepare a commit for!"
exit 1
fi

OLD_VERSION=$(node -e "console.log(require('./package.json').version)")
NEW_VERSION=$1
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
BRANCH_NAME="bump_$NEW_VERSION"
SEMVER_PATTERN="[0-9]*\.[0-9]*\.[0-9]*"

if [[ $(echo "$NEW_VERSION" | sed 's/[0-9]*\.[0-9]*\.[0-9]*/SECRET_REPLACE/g') != "SECRET_REPLACE" ]]; then
echo "Incorrect version format. Must be x.x.x"
exit 1
fi

if [[ -n "$(git status --porcelain)" ]]; then
echo "Repo has changes to the files! Commit or stash the changes to continue."
exit 1
fi

# Checkout a new branch for the version commit
git fetch origin master
git checkout origin/master
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
git branch -D "$BRANCH_NAME" || true
git checkout -b "$BRANCH_NAME"

# Install the dependencies.
yarn install

# Bump the version in package.json and clients/extension/manifest.json
NEEDLE="^ \"version\": \"$SEMVER_PATTERN\""
REPLACEMENT=" \"version\": \"$NEW_VERSION\""

sed -i '' "s/$NEEDLE/$REPLACEMENT/g" package.json clients/extension/manifest.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. handy that you can do both in the same cmd.

do we need an || exit 1 on the sed for failure states? dunno if it'd have one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've got set -euxo pipefail so any failing command should fail

or is that not what you're referring to?


# Update the fixtures with the new version
yarn update:sample-json

# Create the changelog entry
yarn changelog

# Add new contributors to changelog
git --no-pager shortlog -s -e -n "v2.3.0..v${OLD_VERSION}" | cut -f 2 | sort > auto_contribs_prior_to_last
git --no-pager shortlog -s -e -n "v${OLD_VERSION}..HEAD" | cut -f 2 | sort > auto_contribs_since_last
NEW_CONTRIBUTORS=$(comm -13 auto_contribs_prior_to_last auto_contribs_since_last)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL comm ❤️

rm auto_contribs_prior_to_last auto_contribs_since_last

if [[ $(echo "$NEW_CONTRIBUTORS" | wc -l) -gt 1 ]]; then
printf "Thanks to our new contributors 👽🐷🐰🐯🐻! \n$NEW_CONTRIBUTORS\n" | cat - changelog.md > tmp-changelog
mv tmp-changelog changelog.md
fi

git add changelog.md lighthouse-core/test/results/ proto/
git commit -m "$NEW_VERSION"

echo "Version bump commit ready on the ${TXT_BOLD}$BRANCH_NAME${TXT_RESET} branch!"

echo "${TXT_DIM}Press any key to see the git diff, CTRL+C to exit...${TXT_RESET}"
read -n 1 -r unused_variable
git --no-pager diff HEAD^
echo "${TXT_DIM}Press any key to push to GitHub, CTRL+C to exit...${TXT_RESET}"
read -n 1 -r unused_variable
git push -u origin "$BRANCH_NAME"
39 changes: 39 additions & 0 deletions lighthouse-core/scripts/publish-prepare-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_PRISTINE_ROOT="$DIRNAME/../../../lighthouse-pristine"

set -euxo pipefail

bash "$DIRNAME/publish-prepare-pristine.sh"

cd "$LH_PRISTINE_ROOT"

VERSION=$(node -e "console.log(require('./package.json').version)")

if ! git rev-parse "v$VERSION" ; then
if ! git --no-pager log -n 1 --oneline | grep "v$VERSION" ; then
echo "Cannot tag a commit other than the version bump!";
exit 1;
fi

git tag -a "v$VERSION" -m "v$VERSION"
fi

git checkout -f "v$VERSION"

# Install the dependencies.
yarn install

# Build everything
yarn build-all

# Package the extension
node build/build-extension.js package

# Verify the npm package won't include unncessary files
npm pack --dry-run
npx pkgfiles

echo "Make sure the files above look good!"

27 changes: 27 additions & 0 deletions lighthouse-core/scripts/publish-prepare-pristine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_ROOT="$DIRNAME/../.."
cd $LH_ROOT

set -euxo pipefail

# Setup a pristine git environment
cd ../

if [[ ! -e lighthouse-pristine/ ]]; then
git clone git@github.com:GoogleChrome/lighthouse.git lighthouse-pristine
fi

cd lighthouse-pristine/

if [[ -n "$(git status --porcelain)" ]]; then
echo "Pristine repo has changes to the files! Commit or stash the changes to continue."
exit 1
fi

git fetch origin
git fetch --tags
git checkout -f master
git reset --hard origin/master
git clean -fx
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
59 changes: 59 additions & 0 deletions lighthouse-core/scripts/publish-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

TXT_BOLD=$(tput bold)
TXT_DIM=$(tput setaf 245)
TXT_RESET=$(tput sgr0)

DIRNAME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LH_PRISTINE_ROOT="$DIRNAME/../../../lighthouse-pristine"

set -euxo pipefail

bash "$DIRNAME/publish-prepare-pristine.sh"

cd "$LH_PRISTINE_ROOT"

# Install deps
yarn --check-files

# Test err'thing
echo "${TXT_BOLD}Building all the clients..."
yarn build-all

echo "Running the standard test suite..."
yarn test

echo "Running the smoke tests...."
yarn smoke
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dunno about @hoten but i usually run this stuff in another shell since it's so time-consuming.

not sure about a good solution for parallelizing, though.
https://stackoverflow.com/a/38109901/89484 perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah parallel shell business always makes me nervous... good candidate for a perf OYB testing PR? :D


echo "Testing the CLI..."
yarn start "https://example.com" --view

echo "Testing a fresh local install..."
VERSION=$(node -e "console.log(require('./package.json').version)")
npm pack

rm -rf /tmp/lighthouse-local-test || true
mkdir -p /tmp/lighthouse-local-test
cd /tmp/lighthouse-local-test

npm init -y
npm install "$LH_PRISTINE_ROOT/lighthouse-$VERSION.tgz"
npm explore lighthouse -- npm run smoke
npm explore lighthouse -- npm run chrome # try the manual launcher
npm explore lighthouse -- npm run fast -- http://example.com

cd "$LH_PRISTINE_ROOT"
rm -rf /tmp/lighthouse-local-test
rm "lighthouse-$VERSION.tgz"

echo "${TXT_BOLD}Now manually...${TXT_RESET}"
echo "✅ Test the extension. Open chrome://extensions"
echo "${TXT_DIM}Press any key to continue...${TXT_RESET}"
read -n 1 -r unused_variable


echo "✅ Test the viewer. Open http://localhost:8000"
echo " - Works with v4 report? https://gist.github.com/patrickhulce/7251f9eba409f385e4c0424515fe8009"
echo "${TXT_DIM}Press any key to complete the test script...${TXT_RESET}"
read -n 1 -r unused_variable