Skip to content

Instantly share code, notes, and snippets.

@trotzig
Created October 6, 2017 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trotzig/4ee249403111f3520c3659a54707e3f0 to your computer and use it in GitHub Desktop.
Save trotzig/4ee249403111f3520c3659a54707e3f0 to your computer and use it in GitHub Desktop.
An example script for running happo in CI
#!/usr/local/bin/dock bash
# Generates and uploads Happo diffs for the differences between the previous
# and current commit.
set -euo pipefail
PREVIOUS_SHA="$(git rev-parse ${1-HEAD^})"
CURRENT_SHA="$(git rev-parse ${1-HEAD})"
echo "Previous SHA: ${PREVIOUS_SHA}"
echo "Current SHA: ${CURRENT_SHA}"
yarn install
run-happo() {
sha=$1
git checkout --quiet $sha
yarn install
# Here's a good place to drop in build steps for dependencies of the run.
yarn run happo run $sha
}
# Check if we need to generate a baseline
if ! yarn run happo has-report $PREVIOUS_SHA; then
echo "No previous report found for ${PREVIOUS_SHA}. Generating one..."
run-happo $PREVIOUS_SHA
fi
run-happo $CURRENT_SHA
# Finally, post a comment with a link to diffs
summary=$(npm run --silent happo compare $PREVIOUS_SHA $CURRENT_SHA || true)
if [ -n "$summary" ]; then
# Post a comment to the Gerrit patch set linking to the diff(s)
# (Use two newlines to make comment look good in the Gerrit web UI)
message="Message from Happo:
$summary"
echo $message
# https://gerrit-review.googlesource.com/Documentation/cmd-review.html
ssh -p <redacted> <redacted>@<redacted> \
gerrit review \'--message="$message"\' $GERRIT_PATCHSET_REVISION
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment