Skip to content

Commit

Permalink
docs(headless): example script to post report as gist (#5975)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Westgate authored and paulirish committed Sep 6, 2018
1 parent 967ac3b commit 7308b2b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/headless-chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ xvfb-run --server-args='-screen 0, 1024x768x16' \
lighthouse --port=9222 https://github.com
```

## Posting Lighthouse reports to GitHub Gists

Be sure to replace `${GITHUB_OWNER}` and `${GITHUB_TOKEN}` with your own credentials. The code below is tested on Ubuntu.

```sh
apt-get install -y nodejs npm chromium jq
npm install -g lighthouse

# Run lighthouse as JSON, pipe it to jq to wrangle and send it to GitHub Gist via curl
# so Lighthouse Viewer can grab it.
lighthouse "http://localhost" --chrome-flags="--no-sandbox --headless" \
--output json \
| jq -r "{ description: \"YOUR TITLE HERE\", public: \"false\", files: {\"$(date "+%Y%m%d").lighthouse.report.json\": {content: (. | tostring) }}}" \
| curl -sS -X POST -H 'Content-Type: application/json' \
-u ${GITHUB_OWNER}:${GITHUB_TOKEN} \
-d @- https://api.github.com/gists > results.gist

# Let's be nice and add the Lighthouse Viewer link in the Gist description.
GID=$(cat results.gist | jq -r '.id') && \
curl -sS -X POST -H 'Content-Type: application/json' \
-u ${GITHUB_OWNER}:${GITHUB_TOKEN} \
-d "{ \"description\": \"YOUR TITLE HERE - Lighthouse: https://googlechrome.github.io/lighthouse/viewer/?gist=${GID}\" }" "https://api.github.com/gists/${GID}" > updated.gist
```

## Node module

Install:
Expand Down

0 comments on commit 7308b2b

Please sign in to comment.