Skip to content
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

ci: Add test coverage job #27547

Closed
wants to merge 4 commits into from

Conversation

aureleoules
Copy link
Member

This PR adds a new Cirrus job that generates test coverage reports for all pull requests and master using Codecov. It is free for open-source projects.
We can now quickly determine whether a feature that a pull request adds is properly tested.

I've ran a few tests on my own fork, you can check it out here: https://app.codecov.io/gh/aureleoules/bitcoin and a test pull request: https://app.codecov.io/gh/aureleoules/bitcoin/pull/5.

Codecov has a nice feature that highlights the untested chunks of code directly in the GitHub's "Files changed" tab of a pull request. See for example https://github.com/aureleoules/bitcoin/pull/5/files.

Example

image

It can also generate a GitHub comment with a brief summary of the coverage: aureleoules#5 (comment).
Though, that may be undesirable considering Drahtbot already comments on pulls. It can be turned off.

Example

image

These are the permissions Codecov needs to work:
image

19212b4 also fixes #26736.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 30, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK dergoegge, pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27676 (macOS: Bump minimum required runtime version and prepare for building with upstream LLVM by theuni)
  • #21778 (build: LLVM 15 & LLD based macOS toolchain by fanquake)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@aureleoules aureleoules force-pushed the 2023-04-ci-coverage branch 2 times, most recently from 2671acc to 76cb418 Compare May 1, 2023 00:25
@aureleoules
Copy link
Member Author

A backwards compatibility test seems to fail because of BDB, I will fix it if this PR gets Concept ACKed.

@maflcko
Copy link
Member

maflcko commented May 1, 2023

I think it is good to have coverage reports, but I am not sure if it is good to overlay them in the files tab. It might be too invasive? Maybe just a comment with a link is fine?

For the other commits: It would be good for reviewers to explain and motivate them, and explain why they are fine to do and what their tradeoffs are (especially not deleting the gcda files?)

@maflcko
Copy link
Member

maflcko commented May 1, 2023

Also, if the other commits are self-motivated and stand-alone, they can be submitted/reviewed/tested in a separate pull

@aureleoules
Copy link
Member Author

I think it is good to have coverage reports, but I am not sure if it is good to overlay them in the files tab. It might be too invasive? Maybe just a comment with a link is fine?

You can toggle the annotations in the Files tab client-side using the a key.
Or we can fully disable the annotations feature with a custom codecov.yml config file but since they are togglable I think it's fine.

It would be nice if Drahtbot could link to the Codecov report also.

For the other commits: It would be good for reviewers to explain and motivate them, and explain why they are fine to do and what their tradeoffs are (especially not deleting the gcda files?)

I updated the commits descriptions, thanks.

Also, if the other commits are self-motivated and stand-alone, they can be submitted/reviewed/tested in a separate pull

I think they are small enough to be reviewed in this pull request but let me know if you want me to split them.

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Thank you for working on this, I think this would be valuable to have.

It seems like it would be easy to replace codecov with something we could host on our own infra (should that become necessary). For now codecov seems fine to me though.

Read and write access to ... pull requests

Does this mean codecov can push changes to pull request or just that it can comment?

ci/test/06_script_b.sh Outdated Show resolved Hide resolved
They are needed in order to create a coverage report than can be
uploaded to Codecov.
This allows us to add specify additional arguments to the test_runner
when running test coverage.
@aureleoules aureleoules force-pushed the 2023-04-ci-coverage branch 5 times, most recently from 8dc19fc to 0baadae Compare May 27, 2023 22:46
@aureleoules
Copy link
Member Author

Does this mean codecov can push changes to pull request or just that it can comment?

It seems that the permissions for "Pull request" are the following: https://docs.github.com/en/rest/overview/permissions-required-for-github-apps?apiVersion=2022-11-28#pull-requests

So I don't think Codecov is able to push to PRs.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume there is a setting to disable the comment and just have DrahtBot add a link in the form of https://app.codecov.io/gh/{owner}/{repo}/pull/{number} to the summary comment?

.cirrus.yml Outdated Show resolved Hide resolved
@aureleoules
Copy link
Member Author

I presume there is a setting to disable the comment and just have DrahtBot add a link in the form of https://app.codecov.io/gh/{owner}/{repo}/pull/{number} to the summary comment?

Yes there is. Done in 320eb03.

Uploads a test coverage report to Codecov for each pull request and
master.
@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

I really like this feature, I find it very useful. Thanks @aureleoules.

I agree with @dergoegge on that perhaps we could replace it with something hosted on us as well and in the meaintime we can take advantage from Codecov.

As commented by @MarcoFalke on being a bit invasive:

env:
<< : *CIRRUS_EPHEMERAL_WORKER_TEMPLATE_ENV
MAKEJOBS: "-j4"
CODECOV_TOKEN: ENCRYPTED[!ecde4475f93a3607c87a3abaea30a6692c19c658e1b924130ad15b317e44d5f1abdd596984036eada4eeded24384cbd2!]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can be done completely outside of this repo. Otherwise, anyone can print this token and use it?

I think you can set up a mirror, that pulls all open pull requests and runs this task. Then DrahtBot can leave a comment (#27547 (review)) to it. Maybe the GitLab mirror can be used for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, it may be possible to use "differential coverage analysis" from https://github.com/linux-test-project/lcov/releases/tag/v2.0 and somehow publish the report via GitHub Actions CI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, it may be possible to run this completely outside of CI (locally or on a dedicated machine), which updates the summary comment, once and if the coverage report is ready.

@aureleoules
Copy link
Member Author

Thanks for the reviews.

Alternatively, it may be possible to run this completely outside of CI (locally or on a dedicated machine), which updates the summary comment, once and if the coverage report is ready.

I've actually been working on a self-hosted coverage tool for Bitcoin Core recently. It would run independently of this repo. So I'll close this PR.
I'll probably comment on this PR once I have an MVP ready to be presented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run coverage functional tests in parallel
5 participants