我正在尝试根据本指南将灯塔 CI 结果设置/上传为 GitHub 状态检查。
- 根据指南,我安装并授权了 GitHub 应用程序 灯塔CI。
- 然后我把得到的令牌设置为
LHCI_GITHUB_APP_TOKEN
在特拉维斯环境变量中。
这是我的.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)
这些是我的拉取请求和相应的特拉维斯错误日志。
如何为 LHCI 目标正确设置此令牌,以便能够将灯塔 CI 结果作为 GitHub 状态检查上传?谢谢
更新:
根据错误,我在源代码中追溯到这里,我发现需要的令牌实际上是灯塔 CI 服务器令牌。
token: {
type: 'string',
description: 'The Lighthouse CI server token for the project, only applies to `lhci` target.',
},
有关如何设置灯塔CI服务器,请参阅本指南。
所以我认为lhci upload
仅适用于您设置了灯塔 CI 服务器的情况,该服务器不适用于将灯塔 CI 结果设置为 GitHub 状态检查。
但我仍然没有弄清楚如何将灯塔 CI 结果作为 GitHub 状态检查上传。
您需要尊重变量的命名,根据指南,它必须是:LIGHTHOUSE_API_KEY
不是您使用的字符串LHCI_GITHUB_APP_TOKEN
您可以在源代码中看到API_KEY
也可以使用警告:https://github.com/GoogleChromeLabs/lighthousebot/blob/289d17fa9732b41035196fdcbd3e470cc2980b77/runlighthouse.js#L24-L30
感谢 GitHub 上 Johnny 和 Patrick 的帮助。
对于 GitHub 状态检查,我们需要链接到某些内容,因此如果您是 不设置服务器,您可以只使用临时公共存储。
以下是最终版本:
# ...
jobs:
include:
# other stages...
- stage: lighthouse
script:
- yarn build
- lhci autorun --upload.target=temporary-public-storage
addons:
chrome: stable