codecov / self-hosted

Example of how to setup Codecov with docker compose
Other
409 stars 32 forks source link

Github HTTP 401 when posting uploads #16

Closed avx-rchung closed 9 months ago

avx-rchung commented 10 months ago

While trying to send code coverage back to my test installation, using a workflow step like this:

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          name: unittests-go
          flags: unittests
          url: https://codecov.mycompany.com

I am seeing an error:

['error'] There was an error running the uploader: Error uploading to https://codecov.mycompany.com: 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')}

From the api container logs:

{"message": "Received upload request v4", "asctime": "2023-08-29 11:36:28,245", "name": "upload.views.legacy", "levelname": "INFO", "lineno": 79, "pathname": "upload/views/legacy.py", "funcName": "post", "threadName": "MainThread", "version": "v4", "query_params": {"package": "github-action-3.1.4-uploader-0.6.2", "token": "", "branch": "rchung/codecov", "build": "5999522538", "build_url": "https://github.com/myorg/myrepo/actions/runs/5999522538", "commit": "5562c2388c73e28feba4e171ee51088f64c9ec0c", "job": "golang-ut", "pr": "32228", "service": "github-actions", "slug": "myorg/myrepo", "name": "unittests-go", "tag": "", "flags": "unittests", "parent": ""}, "commit": "5562c2388c73e28feba4e171ee51088f64c9ec0c", "logger.name": "upload.views.legacy", "logger.thread_name": "MainThread", "level": "INFO"}
{"message": "Started github-actions tokenless upload", "asctime": "2023-08-29 11:36:28,270", "name": "upload.tokenless.tokenless", "levelname": "INFO", "lineno": 119, "pathname": "upload/views/legacy.py", "funcName": "post", "threadName": "MainThread", "commit": "5562c2388c73e28feba4e171ee51088f64c9ec0c", "repo_name": "myrepo", "job": "golang-ut", "owner": "myorg", "logger.name": "upload.tokenless.tokenless", "logger.thread_name": "MainThread", "level": "INFO"}
{"message": "Github HTTP 401", "asctime": "2023-08-29 11:36:28,427", "name": "shared.torngit.github", "levelname": "WARNING", "lineno": 155, "pathname": "shared/torngit/github.py", "funcName": "make_http_call", "threadName": "ThreadPoolExecutor-50_0", "current_retry": 1, "time_taken": 152.23047501058318, "body": "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/rest\"}", "rlx": "58", "rly": "60", "rlr": "1693310910", "event": "api", "endpoint": "/repos/myorg/myrepo/actions/runs/5999522538", "method": "GET", "bot": null, "repo_slug": "myorg/myrepo", "loggable_token": "notoken", "logger.name": "shared.torngit.github", "logger.thread_name": "ThreadPoolExecutor-50_0", "level": "WARNING"}
{"message": "Request client error ('{\"message\":\"Bad credentials\",\"documentation_url\":\"https://docs.github.com/rest\"}', 'Github API unauthorized error: Unauthorized')", "asctime": "2023-08-29 11:36:28,429", "name": "upload.tokenless.github_actions", "levelname": "WARNING", "lineno": 119, "pathname": "upload/views/legacy.py", "funcName": "post", "threadName": "MainThread", "commit": "5562c2388c73e28feba4e171ee51088f64c9ec0c", "repo_name": "myrepo", "job": "golang-ut", "owner": "myorg", "logger.name": "upload.tokenless.github_actions", "logger.thread_name": "MainThread", "level": "WARNING"}
{"message": "Not Found: /upload/v4", "asctime": "2023-08-29 11:36:28,431", "name": "django.request", "levelname": "WARNING", "lineno": 241, "pathname": "django/utils/log.py", "funcName": "log_response", "threadName": "MainThread", "status_code": 404, "request": "<WSGIRequest: POST '/upload/v4?package=github-action-3.1.4-uploader-0.6.2&token=&branch=rchung%2Fcodecov&build=5999522538&build_url=https%3A%2F%2Fgithub.com%2Fmyorg%2Fmyrepo%2Factions%2Fruns%2F5999522538&commit=5562c2388c73e28feba4e171ee51088f64c9ec0c&job=golang-ut&pr=32228&service=github-actions&slug=myorg%2Fmyrepo&name=unittests-go&tag=&flags=unittests&parent='>", "logger.name": "django.request", "logger.thread_name": "MainThread", "level": "WARNING"}
10.85.128.105 - - [29/Aug/2023:11:36:28 +0000] "POST /upload/v4?package=github-action-3.1.4-uploader-0.6.2&token=&branch=rchung%2Fcodecov&build=5999522538&build_url=https%3A%2F%2Fgithub.com%2Fmyorg%2Fmyrepo%2Factions%2Fruns%2F5999522538&commit=5562c2388c73e28feba4e171ee51088f64c9ec0c&job=golang-ut&pr=32228&service=github-actions&slug=myorg%2Fmyrepo&name=unittests-go&tag=&flags=unittests&parent= HTTP/1.1" 404 171 "-" "-"

From my codecov.yml:

github:
  client_id: "Iv1.xxxxx"
  client_secret: "xxxxx"
  global_upload_token: "<upload-token>"
  webhook_secret: "xxxxx"
  organizations:
    - "myorg"
  integration:
    id: 12345
    pem: "/secrets/github.pem"

Is there some additional setting that is needed to make this work?

LeoQuote commented 10 months ago

Are you using the global_upload_token to upload the report? This is currently not feasible as it's not implemented in self-host server, try the repo level upload token

https://github.com/codecov/feedback/issues/68

trent-codecov commented 10 months ago

Yes tokenless is not ideal. I see you set a token in your action. Something is wrong there, either incorrect token or using global token incorrectly as LeoQuote mentioned.

  1. Ensure the token is correct
  2. If you want to use Global upload token: https://docs.codecov.com/docs/configuration#global-upload-tokens
trent-codecov commented 9 months ago

Please reopen with more info if this is still an issue.