Repository navigation
CI add codecov to GitHub Action workflow - #31941
Conversation
|
This will not fail, but no coverage report will be created, because we are lacking a token. It needs to be collected from codecov and added into the project's secrets, like this guide explains: https://docs.codecov.com/docs/adding-the-codecov-token When I try to sign in to codecov, I am asked to confirm to an oauth which among others lists "act on your behalf". Now, I am unsure. Should I confirm that, or would you rather add the token, @lesteve? |
|
I just added the Codecov token in the GitHub secrets. Let's see what happens with the CI. My guess is that the codecov upload will work because no token is needed on a public repo PR, see doc for more details. It's only when this PR is merged that a Codecov token will be needed for the Codecov upload of the main branch. |
|
One slightly weird thing I noticed in the log is that it uploads multiple Having a quick look at the codecov-action README, maybe we want to use |
…n non-editable mode
|
I pushed a possible fix for the What's special about this build is that we are setting |
| uses: codecov/codecov-action@v5 | ||
| if: ${{ env.COVERAGE == 'true' }} # also condition on that SELECTED_TESTS is empty? | ||
| # This step (also the previous step) should depend on whether we run the whole | ||
| # test suite (maybe adding && env.SELECTED_TESTS == ''): |
There was a problem hiding this comment.
I think for now we can ignore this and leave it for later when we tackle commit-based markers. SELECTED_TESTS is something that is used when the [all random seeds] commit marker is used. When that happens you generally only run a few tests (but with all random seeds) and it wouldn't make sense to upload the coverage because it would be small.
There was a problem hiding this comment.
Ignoring it for now sounds like a practical way to deal with it. Do you think this comment helps remind us what we need to do here, or should I remove it?
There was a problem hiding this comment.
Leave the comment if you prefer, but I would put a TODO in front to make it slightly clearer that we are planning to tackle it
| # This step (also the previous step) should depend on whether we run the whole | ||
| # test suite (maybe adding && env.SELECTED_TESTS == ''): | ||
| if: ${{ env.COVERAGE == 'true' }} |
There was a problem hiding this comment.
In Azure we here test if SELECTED_TESTS is empty (like adding && env.SELECTED_TESTS == '' in the condition below).
Right now, we cannot do that here, because get_selected_tests.py only seems to create an environmental variable valid in azure I believe and also calls get_commit_message.py and that's a separate task that is discussed here: #31832 (comment). I'm not sure if the discussion let to us having a plan and which one.
After SELECTED_TESTS is available here, we could add this condition in this step, or, alternatively, set COVERAGE: 'false' if SELECTED_TESTS is not empty early on, so that codecov doesn't run at all and we save this CI time.
|
|
||
| # Copy the combined coverage file to the root of the repository: | ||
| cp $TEST_DIR/coverage.xml $BUILD_REPOSITORY_LOCALPATH | ||
| cp $TEST_DIR/coverage.xml . |
There was a problem hiding this comment.
Comment for potential other reviewers: BUILD_REPOSITORY_LOCALPATH is a Azure-specific environment variable that points where the scikit-learn root folder is located.
Maybe GitHub has an equivalent environment variable, but it feels slightly simpler to rely on the assumption that the current working directory is the same as the scikit-learn repo root folder.
| # report that otherwise hides the test failures and forces long scrolls in | ||
| # the CI logs. | ||
| export COVERAGE_PROCESS_START="$BUILD_SOURCESDIRECTORY/.coveragerc" | ||
| export COVERAGE_PROCESS_START="$CHECKOUT_FOLDER/.coveragerc" |
There was a problem hiding this comment.
Similar comment as https://github.com/scikit-learn/scikit-learn/pull/31941/files#r2276870682. It feels slightly preferable to rely on the assumption that the current working directory is the scikit-learn repo root folder.
| if: ${{ env.COVERAGE == 'true' }} | ||
|
|
||
| - name: Upload coverage report to Codecov | ||
| uses: codecov/codecov-action@v5 |
There was a problem hiding this comment.
I guess one thing to think about for potential reviewers is whether we are OK with using an external GitHub action. Full disclosure: a few years ago the Codecov uploader was compromised see this.
The only secret being exposed would be the Codecov token. I am not sure how much harm can be done with this token (upload fake coverage reports to Codecov sure but something else?).
An alternative would be to use our Azure script build_tools/azure/upload_coverage.shbuild_tools/azure/upload_codecov.sh but it would need to be adapted for GitHub, it uses Azure-specific BUILD_ environment variables.
There was a problem hiding this comment.
It is the build_tools/azure/upload_codecov.sh file.
There was a problem hiding this comment.
The only secret being exposed would be the Codecov token. I am not sure how much harm can be done with this token (upload fake coverage reports to Codecov sure but something else?).
The permissions is set to read for this workflow. The only other possibly harmful side effect would be cache poisoning but based on my understanding of how cache isolation work in GitHub Actions this should not be able to taint our release process.
| TEST_CMD="$TEST_CMD --cov-config='$COVERAGE_PROCESS_START' --cov sklearn --cov-report=" | ||
| TEST_CMD="$TEST_CMD --cov-config='$COVERAGE_PROCESS_START' --cov=sklearn --cov-report=" |
There was a problem hiding this comment.
This diff was necessary to fix the order of the cli arguments.
For some reason, this was evaluated as TEST_CMD="$TEST_CMD --cov-config='$COVERAGE_PROCESS_START' --cov --cov-report= sklearn" when eval "$TEST_CMD" ran and thus not understood. With the = it works on azure and github actions.
There was a problem hiding this comment.
I don't understand why there is a = without anything else after for the --cov-report flag. Is it really necessary?
EDIT: please ignore, this is explained in the comment above.
ogrisel
left a comment
There was a problem hiding this comment.
I took a look at the CI run https://github.com/scikit-learn/scikit-learn/actions/runs/17209606816/job/48817950066?pr=31941#step:8:355 and the codecov report and everything looks fine. The github actions upload seem to have properly been associated with this PR:
The diff LGTM as well. Thanks for the improvement @StefanieSenger and @lesteve.
Co-authored-by: Loïc Estève <[email protected]>
Reference Issues/PRs
Follow up on #31832
What does this implement/fix? Explain your changes.
This PR adds steps to the github actions workflow (
unit-tests.yml) that merge and upload codecov coverage reports.Thanks for your support @lesteve!