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 lhci dogfood script to travis #9677

Merged
merged 9 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
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
47 changes: 47 additions & 0 deletions lighthouse-core/scripts/dogfood-lhci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -euox pipefail
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the benefit of doing this here instead of in the /bin/bash shebang? all my personal scripts look like this:

#!/bin/bash -ex

...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no benefit I'm aware of, just personal habit I suppose.

is there a benefit to doing it in the shebang? :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

i like one liners i guess

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh after some googling I remembered I started this habit back at a company that used #!/usr/bin/env bash in all our scripts where the one-liner wasn't an option, so I guess that's one benefit of this set method is that it can be consistent across those two methods :)


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

Choose a reason for hiding this comment

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

LHCI_CANARY_SERVER_TOKEN

does this mean only PRs from core contributors will get this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could've sworn I replied to this already...

anyhoo, yes it's only available to core contributors at the moment, but that's not a hard requirement, we could loosen this and hardcode them if we wanted later they're not really that secret since you could find them out yourself given the URL of our server.


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
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
yarn now-build
cp ./dist/now/english/index.html ./lighthouse-cli/test/fixtures/lhci.report.html

# Start up a test server.
yarn static-server &
# Wait for the server to start before hitting it with data.
sleep 10
# Install LHCI
npm install -g @lhci/cli@next
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
# 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 $!
Copy link
Member

Choose a reason for hiding this comment

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

kill $(jobs -p) would nuke all child processes. (in case the lhci commands also did backgrounded stuff.

but they don't. so it doesnt really matter. :)

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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