Lighthouse-ci: How to upload the Lighthouse CI results as GitHub status checks?

Created on 30 Nov 2019  路  3Comments  路  Source: GoogleChrome/lighthouse-ci

Originally asked at Stack Overflow. It would be great if someone can help me point the direction. Thanks!


I am trying to set/upload the Lighthouse CI results as GitHub status checks based on this guide.

  1. Based on the guide, I installed and authorized the GitHub app
    Lighthouse CI.
  2. Then I set the token I got as LHCI_GITHUB_APP_TOKEN
    in the Travis Environment Variables.

This is the part of my .travis.yml.

language: node_js
node_js:
  - "12"

branches:
  only:
    - master

cache: yarn

before_install:
  - yarn global add @lhci/cli

install:
  - yarn install --frozen-lockfile

jobs:
  include:
    # other stages...

    - stage: lighthouse
      script:
        - yarn build
        - lhci autorun
      after_script:
        # Set the results as GitHub status checks
        - lhci upload
      addons:
        chrome: stable

lhci autorun succeed runnning.

However, when lhci upload runs, it returns error

Error: Must provide token for LHCI target
    at runLHCITarget (/home/travis/.config/yarn/global/node_modules/@lhci/cli/src/upload/upload.js:212:29)
    at Object.runCommand (/home/travis/.config/yarn/global/node_modules/@lhci/cli/src/upload/upload.js:323:14)
    at run (/home/travis/.config/yarn/global/node_modules/@lhci/cli/src/cli.js:90:23)
    at Object.<anonymous> (/home/travis/.config/yarn/global/node_modules/@lhci/cli/src/cli.js:118:1)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)

These are my pull request and corresponding Travis error log.

How to set up this token for LHCI target correctly to be able to upload the Lighthouse CI results as GitHub status checks? Thanks


UPDATE:

Based on the error, I traced to here in the source code, I found out that the token that requires is actually the Lighthouse CI server token.

token: {
  type: 'string',
  description: 'The Lighthouse CI server token for the project, only applies to `lhci` target.',
},

For how to set up t he Lighthouse CI server, please refer to this guide.

So I think lhci upload only applies if you have set up a Lighthouse CI server, which is not for setting the Lighthouse CI results as GitHub status checks.

But still I haven't figured out how to upload the Lighthouse CI results as GitHub status checks.

question

Most helpful comment

So I think lhci upload only applies if you have set up a Lighthouse CI server, which is not for setting the Lighthouse CI results as GitHub status checks.

I think what you need to do is to change the upload target arg to temporary-public-storage.

Here are the docs to the Ci

All 3 comments

So I think lhci upload only applies if you have set up a Lighthouse CI server, which is not for setting the Lighthouse CI results as GitHub status checks.

I think what you need to do is to change the upload target arg to temporary-public-storage.

Here are the docs to the Ci

@jzabala got it exactly right :)

For the GitHub status check we need to link to something so if you're not setting up the server you can just use temporary-public-storage.

In your example..

  1. Change lhci autorun to lhci autorun --upload.target=temporary-public-storage
  2. Remove after_success: - lhci upload autorun will run upload for you.

Thank you so much @jzabala @patrickhulce .
It works perfect https://github.com/Hongbo-Miao/hongbomiao.com/pull/378 now!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xavierfoucrier picture xavierfoucrier  路  4Comments

felixck12 picture felixck12  路  4Comments

lili21 picture lili21  路  4Comments

GreedyA1 picture GreedyA1  路  3Comments

mathiasbynens picture mathiasbynens  路  4Comments