为什么 GitHub Actions 中的 Codecov 上传步骤找不到令牌?

问题描述 投票:0回答:1

背景

我一直在帮助维护的公共 GitHub 存储库(“ncompare

”)中使用 GitHub Actions 和 
codecov-action,但最近这个 codecov 上传步骤(在这个测试工作流程中)开始引发错误,有关没有 codecov 令牌的消息。

令牌以“CODECOV_TOKEN”名称保存为存储库机密。

错误有两种形式。第一个是(请参阅完整日志此处):

debug - 2024-04-09 13:05:05,527 -- Starting create commit process --- {"commit_sha": "dc6df2f3530a6c18f6b23ab63a8549754fae6e1f", "parent_sha": null, "pr": null, "branch": "develop", "slug": "nasa/ncompare", "token": null, "service": "github", "enterprise_url": null}
Error: Codecov token not found. Please provide Codecov token with -t flag.
Error: Codecov: Failed to properly create commit: The process '/home/runner/work/_actions/codecov/codecov-action/v4/dist/codecov' failed with exit code 1

第二种形式是(请参阅完整日志此处):

[2024-04-08T18:04:32.790Z] ['info'] Pinging Codecov: https://codecov.io/upload/v4?package=github-action-3.1.6-uploader-0.7.2&token=*******&branch=develop&build=8604645331&build_url=https%3A%2F%2Fgithub.com%2Fnasa%2Fncompare%2Factions%2Fruns%2F8604645331&commit=0c5f7f070497072c670fca7cb4a65d97a4b6ce25&job=CI&pr=&service=github-actions&slug=nasa%2Fncompare&name=&tag=&flags=&parent=
[2024-04-08T18:04:32.790Z] ['verbose'] Passed token was 0 characters long
[2024-04-08T18:04:32.790Z] ['verbose'] https://codecov.io/upload/v4?package=github-action-3.1.6-uploader-0.7.2&branch=develop&build=8604645331&build_url=https%3A%2F%2Fgithub.com%2Fnasa%2Fncompare%2Factions%2Fruns%2F8604645331&commit=0c5f7f070497072c670fca7cb4a65d97a4b6ce25&job=CI&pr=&service=github-actions&slug=nasa%2Fncompare&name=&tag=&flags=&parent=
        Content-Type: 'text/plain'
        Content-Encoding: 'gzip'
        X-Reduced-Redundancy: 'false'
[2024-04-08T18:04:32.989Z] ['error'] There was an error running the uploader: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 404 - {'detail': ErrorDetail(string='Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.', code='not_found')}
[2024-04-08T18:04:32.990Z] ['verbose'] The error stack is: Error: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 404 - {'detail': ErrorDetail(string='Unable to locate build via Github Actions API. Please upload with the Codecov repository upload token to resolve issue.', code='not_found')}
    at main (/snapshot/repo/dist/src/index.js)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[2024-04-08T18:04:32.990Z] ['verbose'] End of uploader: 552 milliseconds
Error: Codecov: Failed to properly upload: The process '/home/runner/work/_actions/codecov/codecov-action/v3/dist/codecov' failed with exit code 255

我尝试过的事情

  • 我尝试过使用
    codecov-action
    的版本 3 和 4。
  • 我尝试过重新生成并保存新的 CODECOV 代币
  • 我已为 codecov-action 参数尝试了以下两种语法:
with:
  token: ${{ secrets.CODECOV_TOKEN }}
env:
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
github-actions codecov
1个回答
0
投票

根据您的工作流程文件,您将它们触发为

workflow_call
。要解决丢失令牌的问题,您必须将您的秘密传递到
workflow_call
中的
reusable_run_tests.yml
工作中。

这是一个基于您的代码的示例:

resuable_run_tests.yml

on:
  workflow_call:
    secrets:
      codecov_token:
        required: true
  workflow_dispatch:

jobs:
  build_and_test:
    runs-on: ubuntu-latest
...
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.codecov_token }}
          verbose: true

然后在您的调用者作业中(在您的情况下位于

pull-request-received.yml
中),您通过传入 CodeCov 令牌作为存储库中的秘密来调用上面的作业。这样,您就不会暴露您的 CodeCov 令牌。

jobs:
  build_and_test:
    uses: ./.github/workflows/reusable_run_tests.yml
    secrets:
      codecov_token: ${{ secrets.CODECOV_TOKEN }}

我希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.