如何通过GitHub状态检查上传Lighthouse CI结果?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何通过GitHub状态检查上传Lighthouse CI结果?相关的知识,希望对你有一定的参考价值。

我正在尝试基于Lighthouse CI设置/上传this guide结果作为GitHub状态检查。

  1. 根据指南,我安装并授权了GitHub应用灯塔CI。
  2. 然后我将获得的令牌设置为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运行时,它返回错误

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和对应的Travis error log

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


UPDATE:

基于错误,我在源代码中找到了here,发现所需的令牌实际上是Lighthouse CI服务器令牌。

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

关于如何设置Lighthouse CI服务器,请参阅this guide

因此,我认为lhci upload仅在您设置了Lighthouse CI服务器时才适用,而不是将Lighthouse CI结果设置为GitHub状态检查。

但是我仍然不知道如何通过GitHub状态检查来上传Lighthouse CI结果。

答案

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

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

另一答案

感谢约翰尼和帕特里克GitHub的帮助。

对于GitHub状态检查,我们需要链接到某些内容,因此,如果您不设置服务器,您可以只使用临时公共存储。

下面是最终版本:

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

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

以上是关于如何通过GitHub状态检查上传Lighthouse CI结果?的主要内容,如果未能解决你的问题,请参考以下文章

如何将本地代码使用Git上传至Github

上传本地仓库到github

如何将项目上传到Github

如何进行监控上传状态?

把上传Github的代码添加Cocoapods支持

如何使用 phpseclib 通过 SFTP 检查上传的文件是不是存在