我正在尝试基于Lighthouse CI设置/上传this guide结果作为GitHub状态检查。
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结果?谢谢
更新:
基于该错误,我在源代码中追踪到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结果。
答案 0 :(得分:0)
您需要尊重变量的命名,按照指南,变量的名称必须是:LIGHTHOUSE_API_KEY
而不是您使用的字符串LHCI_GITHUB_APP_TOKEN
您可以在源代码中看到API_KEY
也可以使用警告:https://github.com/GoogleChromeLabs/lighthousebot/blob/289d17fa9732b41035196fdcbd3e470cc2980b77/runlighthouse.js#L24-L30
答案 1 :(得分:0)
感谢约翰尼和帕特里克在GitHub上提供的帮助。
对于GitHub状态检查,我们需要链接到某些内容,因此如果您 不设置服务器,您可以使用临时公共存储。
以下是最终版本:
# ...
jobs:
include:
# other stages...
- stage: lighthouse
script:
- yarn build
- lhci autorun --upload.target=temporary-public-storage
addons:
chrome: stable