Skip to content

CI: Fall back to codecov@v3 when @v4 has no token, add coveralls #5743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Jun 26, 2024

The merge of #5734 on master (merge commit on master: 5bd9b86) uses OpenID Connect (OIDC) to have a token-based coverage upload to Codecov.

But because OpenID Connect is only available for builds from users that use OIDC:

  • The build of the merged commit on master (5bd9b86) failed to upload because it has no context of the user pushing the merged PR: OIDC is not available during that build and the upload fails:

    Run codecov/codecov-action@v4
    evenName: push
    Error: Codecov: Failed to get OIDC token with url: https://codecov.io./ Error message: Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable

Docs on the Codecov action and using OIDC: https://github.com/marketplace/actions/codecov#using-oidc

The most reliable way to upload to codecov.io is codecov@v4 with the CODECOV_TOKEN secret.

  • It needs secrets.CODECOV_TOKEN, generated in codecov.io by the repo or organisation owner.
    These are the possible ways to set it up:
    • Only for one repo / for each repo individually:
      • Generated by the owner xen-api repo owner (@robhoes) and added as repo secret to xen-api, or
    • For all repos in the organisation:
      • Generated by the org owner of xapi-project and added as organisation secret to the xapi-project organisation.
    • Precondition: The respective owner needs to have confidence (trust) that Codecov will not hurt the project.
      • When generating the token, github will show a very scary message saying that Codecov can impersonate the user who generates the secret token (using the given account permission).
      • The secret token is guarded by GitHub action of course.
      • As long as the repo or organiation owner use a secure environment to copy and paste the generated CODECOV_TOKEN from codecov into the repo or respective organisation secret on GitHub.
        • this is of course key: It must not be stored by any other means besides as repo/organisation secret for the GitHub action workflows.
        • The other trusted party is codecov.io, which must be trusted to not abuse the trust.

Without that hurdle jumped, we only have the option of fallbacks:

  • Fall back to OIDC when the OIDC is available from the user
    • It will be used automatically on PR workflows, but not always on push workflows.
  • If that fails too, we can only fall back to v3, with the known unreliable uploads due to GitHub's API rate-limiting.
    • This fallback is the last resort for the coverage uploads on branches/pushes OIDC is not accessible.
  • Upload to coveralls.io, which was already used by the xen-api repository in the past.

This PR implements all these fallbacks. These are useful for the xapi-project/xen-api and for working on and with forks.

If xapi-project/xen-api adopts the setup of the CODECOV_TOKEN, also forks of it would use it.
GitHub is trusted to protect the tokens like it it is trusted with all other GitHub action secrets.

Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
@bernhardkaindl bernhardkaindl requested a review from psafont June 26, 2024 22:19
@bernhardkaindl bernhardkaindl changed the title Fall back to codecov v3 when v4 has no token, add coveralls CI: Fall back to codecov@v3 when @v4 has no token, add coveralls Jun 26, 2024
@psafont
Copy link
Member

psafont commented Jun 27, 2024

I'd rather revert the change that introduced v4, or use coveralls rather than adding this much complexity. Is coveralls more stable than codecov?

@lindig
Copy link
Contributor

lindig commented Jun 27, 2024

I agree with Pau; complexity in these nice-to-have features will cause breakage down the line that will be expensive to fix.

@psafont
Copy link
Member

psafont commented Jun 27, 2024

coveralls works well to upload coverage for both python versions: https://coveralls.io/builds/68333955

@psafont psafont closed this Jun 27, 2024
@bernhardkaindl bernhardkaindl deleted the codecov-fallback branch July 10, 2024 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants