codecov-action icon indicating copy to clipboard operation
codecov-action copied to clipboard

Is it supported to upload coverage from forked repo to pullrequest of upstream repo

Open hernot opened this issue 4 years ago • 1 comments

I'm trying to use codecov/codecov-action@v2 to upload of coverage collected on push run of forked repo to specific pullrequest on upstream repo. I Tried the following two versions of the github action step

# Variant 1
on: [push,pull_request_target]
# ... skipped
jobs:
  build:
    # ... skipped
    steps:
       # ... skipped
       - name: Upload coverage for pull request
         if: ${{ success() && env.PULL_NUMBER >= 0 }}
         uses: codecov/codecov-action@v2
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
           slug: <target-name>/<repo>
           files: coverage.xml
           override_pr: ${{env.PULL_NUMBER}}
           fail_ci_if_error: true
           verbose: true
# NOTE: The environment variable `PULL_NIUMBER` is provided by an earlier step using script action
# Variant 2
on: [push,pull_request_target]
# ... skipped
jobs:
  build:
    # ... skipped
    steps:
       # ... skipped
       - name: Upload coverage for pull request
         if: ${{ success() && env.PULL_NUMBER >= 0 }}
         uses: codecov/codecov-action@v2
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
           files: coverage.xml
           override_pr: ${{env.PULL_NUMBER}}
           fail_ci_if_error: true
           verbose: true
# NOTE: The environment variable `PULL_NIUMBER` is provided by an earlier step using script action

Version 1 results in the error

Error: Codecov: Failed to properly upload: The process 'D:\a\_actions\codecov\codecov-action\v2\dist\codecov.exe' failed with exit code 4294967295

Which is logic as the puild_url parameter in the upload url points to the target repo indicated by slug

https://codecov.io/upload/v4?package=github-action-2.0.2-uploader-0.1.0&branch=<repo>-5-RC&build=1121318273&build_url=https%3A%2F%2Fgithub.com%2F<target-name>%2F<repo>%2Factions%2Fruns%2F1121318273&commit=6f73c156bf353ab1d26ed536f77a5d7358680e72&job=Python%20package&pr=149&service=github-actions&slug=<target-name>/<repo>&name=&tag=&flags=&parent=

The second variant results in the error

Error uploading to Codecov when fetching PUT (inner): 404 {'detail': ErrorDetail(string='Could not find a repository, try using upload token', code='not_found')}

which is logic as for my fork of the repo there does not exist a codecove account and should not exist and thus the upload url which tries to upload for my repo has to fail

 https://codecov.io/upload/v4?package=github-action-2.0.2-uploader-0.1.0&branch=<repo>-5-RC&build=1121289556&build_url=https%3A%2F%2Fgithub.com%2Fhernot%2F<repo>%2Factions%2Fruns%2F1121289556&commit=0687ebe7af5311d8321afbf8f248953fd0b51435&job=Python%20package&pr=149&service=github-actions&slug=hernot/<repo>&name=&tag=&flags=&parent=

So my question is which other parameters do i have to overide or set so that the coverage of the build in my repo is pushed to pullrequest issue in codecove account linked to /repo. And that using the tokenless upload as i do not have access to token of /repo and should not have. This worklow is intended as replacement for Travis-CI runner and Appveyor-CI runner and thus should work on all current and future forks of <target-name>/<repo> and not specifically for my fork.

hernot avatar Aug 11 '21 19:08 hernot

OK think i found the problem. Its not in action but rather in understanding how workflows work. When they are invoked on which events and which repo.
The down is that it seems that editing or adding workflows through pullrequest have no affect on pull_request.synchronize or the other pull_request types until workflow has been merged into at least base branch of pullrequest. As long as the changes can be also tested on push event in forked repo that is fair but when it comes to things like uploading codecov report which seem to work only when run on base repo or owner of base repo has set permissions to share token and approved it for contributor repo than testing and verifying is not possible by contributor.

Hope this is really the explanation why uploading does not work as expected. Especially as uploader seems to work a bit different than python-codecov module.

hernot avatar Aug 12 '21 22:08 hernot