Skip to content

Commit

Permalink
misc: add releasing scripts (#8387)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and connorjclark committed Apr 30, 2019
1 parent f75c12e commit c6939bb
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 71 deletions.
90 changes: 19 additions & 71 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,73 +31,22 @@ 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/release/release-test.sh
# Prepare the commit, replace x.x.x with the desired version
bash ./lighthouse-core/scripts/release/release-prepare-commit.sh x.x.x

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

# Run the tests again :)
bash ./lighthouse-core/scripts/release/release-test.sh
# Package everything for publishing
bash ./lighthouse-core/scripts/release/release-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 "
open https://chrome.google.com/webstore/developer/edit/blipmdconlkpinefehnmjammfjpmpbjk
echo "Upload the package zip to CWS dev dashboard"
# Be in lighthouse-extension-owners group
# Open <https://chrome.google.com/webstore/developer/dashboard>
Expand All @@ -106,12 +55,11 @@ 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"
# Make sure you're in the Lighthouse pristine repo we just tested.
cd ../lighthouse-pristine
# Publish to NPM
npm publish
# Publish viewer
yarn deploy-viewer

# * Tell the world!!! *
Expand Down
17 changes: 17 additions & 0 deletions lighthouse-core/scripts/release/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
76 changes: 76 additions & 0 deletions lighthouse-core/scripts/release/publish-prepare-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/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
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
git log -n 1
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

# 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)
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/release/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/release-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/release/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 -fdx # Forcibly clean all untracked files and directories, including `.gitignore`d ones.
59 changes: 59 additions & 0 deletions lighthouse-core/scripts/release/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/release-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

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

0 comments on commit c6939bb

Please sign in to comment.