-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
CI add codecov to GitHub Action workflow #31941
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
base: main
Are you sure you want to change the base?
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 |
.github/workflows/unit-tests.yml
Outdated
@@ -88,9 +88,10 @@ jobs: | |||
|
|||
- name: Upload coverage report to Codecov | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.github/workflows/unit-tests.yml
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
.codecov.yml
Outdated
after_n_builds: 6 | ||
# Prevent codecov from calculating the coverage results before all expected uploads | ||
# are in. This value is set to the total number of jobs uploading coverage reports: | ||
# 6 Azure Pipeline jobs plus 1 GitHub Actions job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this line because the exact number of Azure and GitHub jobs will change during the transition to GHA. IMO this line will become outdated quickly because it's close to impossible to remember to update it each time we move a CI build to GHA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have removed it. The idea had been to make it easy to detect if the number is out of date. Let's see if we manage to remember to change this number. 🤞 😄
pushd $TEST_DIR | ||
coverage combine --append | ||
coverage xml | ||
popd | ||
|
||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
# CI logs. The coverage data is consolidated by codecov to get an online | ||
# web report across all the platforms so there is no need for this text | ||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.sh
but it would need to be adapted for GitHub, it uses Azure-specific BUILD_
environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the build_tools/azure/upload_codecov.sh
file.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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!