如何将 Lighthouse CI 结果上传为 GitHub 状态检查?

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

我正在尝试 set/upload Lighthouse CI results as GitHub status checks based on this guide

  1. 根据指南,我安装并授权了 GitHub 应用程序 灯塔 CI.
  2. 然后我将得到的token设置为LHCI_GITHUB_APP_TOKEN 在 Travis 环境变量中。

这是我的部分 .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运行成功

但是,当lhci upload运行时,它returns错误

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)

这些是我的pull request and corresponding Travis error log

如何为 LHCI 目标正确设置此令牌,以便能够将 Lighthouse CI 结果作为 GitHub 状态检查上传?谢谢


更新:

根据报错,我在源码中追溯here,发现需要的token其实是Lighthouse CI server token

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

LighthouseCI服务器的设置方法,请参考this guide

所以我认为 lhci upload 仅在您设置了 Lighthouse CI 服务器时才适用,这不适用于将 Lighthouse CI 结果设置为 GitHub 状态检查.

但我仍然没有弄清楚如何上传 Lighthouse CI 结果作为 GitHub 状态检查。

您需要尊重变量的命名,根据指南,它必须是:LIGHTHOUSE_API_KEY 而不是您使用的字符串 LHCI_GITHUB_APP_TOKEN

您可以在源代码中看到 API_KEY 也可以使用警告:https://github.com/GoogleChromeLabs/lighthousebot/blob/289d17fa9732b41035196fdcbd3e470cc2980b77/runlighthouse.js#L24-L30

感谢 Johnny 和 Patrick 在 GitHub 上的帮助。

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.

最终版本如下:

# ...
jobs:
  include:
    # other stages...

    - stage: lighthouse
      script:
        - yarn build
        - lhci autorun --upload.target=temporary-public-storage
      addons:
        chrome: stable