Skip to content

Commit

Permalink
misc: add lhci dogfood script to travis (#9677)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Sep 25, 2019
1 parent 6cfa6c7 commit 6ff02e4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -39,6 +39,7 @@ script:
- yarn test-viewer
- yarn test-lantern
- yarn i18n:checks
- yarn dogfood-lhci
before_cache:
# nyc, jest and other projects store files in here. They mess up the travis build cache.
- rm -rf ./node_modules/.cache/
Expand Down
52 changes: 52 additions & 0 deletions lighthouse-core/scripts/dogfood-lhci.sh
@@ -0,0 +1,52 @@
#!/bin/bash

set -euox pipefail

# This script requires LHCI_CANARY_SERVER_URL and LHCI_CANARY_SERVER_TOKEN variables to be set.

if [[ -z "$LHCI_CANARY_SERVER_TOKEN" ]]; then
echo "No server token available, skipping.";
exit 0;
fi

if [[ "$TRAVIS_NODE_VERSION" != "10" ]]; then
echo "Not running dogfood script on node versions other than 10";
exit 0;
fi


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

# Testing lhci takes time and the server ain't massive, we'll only run the tests if we touched files that affect the report.
CHANGED_FILES=""
if [[ "$CI" ]]; then
CHANGED_FILES=$(git --no-pager diff --name-only "$TRAVIS_COMMIT_RANGE")
else
CHANGED_FILES=$(git --no-pager diff --name-only master)
fi

printf "Determined the following files have been touched:\n\n$CHANGED_FILES\n\n"

if ! echo "$CHANGED_FILES" | grep -E 'report|lhci' > /dev/null; then
echo "No report files affected, skipping lhci checks."
exit 0
fi

# Generate an HTML report and copy into static-server directory for serving.
yarn now-build
cp ./dist/now/english/index.html ./lighthouse-cli/test/fixtures/lhci.report.html

# Install LHCI
npm install -g @lhci/cli@next
# Start up a test server.
yarn static-server &
# Wait for the server to start before hitting it with data.
sleep 10
# Collect our LHCI results.
lhci collect --url=http://localhost:10200/lhci.report.html
# Upload the results to our canary server.
lhci upload --serverBaseUrl="$LHCI_CANARY_SERVER_URL" --token="$LHCI_CANARY_SERVER_TOKEN"

# Kill the static server from earlier.
kill $!
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"deploy-viewer": "yarn build-viewer --deploy",
"now-build": "node lighthouse-core/scripts/build-report-for-autodeployment.js",
"bundlesize": "bundlesize",
"dogfood-lhci": "./lighthouse-core/scripts/dogfood-lhci.sh",
"timing-trace": "node lighthouse-core/scripts/generate-timing-trace.js",
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file",
"type-check": "tsc -p . && tsc -p lighthouse-viewer/",
Expand Down

0 comments on commit 6ff02e4

Please sign in to comment.