Skip to content

CI Handle [all random seeds] commit marker in GHA - #32505

Merged
lesteve merged 32 commits into
scikit-learn:mainfrom
thomass-dev:ci-retrieve-commit-message-for-all-random-seed-marker
Oct 23, 2025
Merged

lesteve merged 32 commits into
scikit-learn:mainfrom
thomass-dev:ci-retrieve-commit-message-for-all-random-seed-marker

Conversation

@thomass-dev

@thomass-dev thomass-dev commented Oct 15, 2025 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Partially addresses #32434.

changes of behaviour based on commit markers e.g. [float32], [all random seeds]. I had a look and my thinking so far would be to refrain from using CI-provider specific environment variable in bash scripts (e.g. Azure-specific BUILD_REASON is currently used in build_tools/test_script.sh or in build_tools/azure/get_commit_message.py but I would avoid doing a similar thing for GHA). Instead we should have a step in the yaml that sets environment variable (or job output if we think it's better to use job output), which the bash script can then use.

[...]
[all random seeds] is next

What does this implement/fix? Explain your changes.

@github-actions

github-actions Bot commented Oct 15, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: f7e1e42. Link to the linter CI: here

@lesteve lesteve mentioned this pull request Oct 15, 2025
11 of 14 tasks
@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch 5 times, most recently from e70b16d to 4abdb6a Compare October 22, 2025 13:56
@thomass-dev thomass-dev changed the title CI Use COMMIT_MESSAGE in build_tools/azure/get_commit_message.py CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] Oct 22, 2025
@thomass-dev thomass-dev changed the title CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] marker Oct 22, 2025
@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch from 4abdb6a to cbd1276 Compare October 22, 2025 14:04
@thomass-dev thomass-dev changed the title CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] marker CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] marker in GHA Oct 22, 2025
@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch from cbd1276 to 982efb0 Compare October 22, 2025 14:14
@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch 2 times, most recently from c4420ca to c1639d5 Compare October 22, 2025 14:41
test_kmeans_convergence
test_gnb_prior
@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch from c1639d5 to 6938e38 Compare October 22, 2025 14:44

@lesteve lesteve left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the general direction

It seems like in your last commit the CI is red see build log

The problem seems to be a missing quote around the test names
-k test_kmeans_convergence or test_gnb_prior should be -k "test_kmeans_convergence or test_gnb_prior"

Comment thread build_tools/azure/get_commit_message.py Outdated
"get_commit_message not supported outside Azure for now, "
"returning empty commit message"

if "COMMIT_MESSAGE" in os.environ or os.environ.get("GITHUB_ACTIONS", False):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would do something like, wording improvements more than welcome.

if "BUILD_SOURCEVERSIONMESSAGE" not is os.environ:
    raise RuntimeError("This legacy script should only be used on Azure. On GitHub actions, use the 'COMMIT_MESSAGE' environment variable")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7660c6c (mix between my solution and yours).

Comment thread build_tools/azure/get_commit_message.py Outdated
)
return ""

logger.debug("`commit_message` coming from Azure")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this logging is not really necessary, if you get an error above you are not in Azure, if you don't get an error, well then you are on Azure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1f89c61.

Comment thread build_tools/azure/get_selected_tests.py Outdated
<test_name_2>
...
"""
if "SELECTED_TESTS" in os.environ or os.environ.get("GITHUB_ACTIONS", False):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would use a similar logic as for the get_commit_message.py, something like this:

if "BUILD_REASON" not in os.environ:
    raise RuntimeError("This legacy script is supposed to be used only on Azure. On GitHub Actions use the `SELECTED_TESTS` environment variable directly")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7660c6c (mix between my solution and yours).

Comment thread build_tools/azure/get_selected_tests.py Outdated
print(f"selected tests: {selected_tests}") # helps debugging
else:
print("no selected tests")
# set the environment variable to be propagated to other steps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a good reason to change this? As a reviewer any changes that requires me having to think will make me unhappy 😅. Also since this is a legacy script, it will go away soonish and I would tweak it only when really needed.

@thomass-dev thomass-dev Oct 23, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to standardize with get_commit_message.py: the variable SELECTED_TESTS is always set, even if there is no selected tests.

With the previous implementation, SELECTED_TESTS is only set when there is selected tests.

In addition, as get_commit_message.py, i wanted to call it directly in test_script.sh.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Revert in 627a7ea.

echo EOF
} >> "${GITHUB_OUTPUT}"

retrieve-selected-tests:

@lesteve lesteve Oct 23, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The logic looks good.

I am wondering whether moving this to a step in the retrieve-commit-message would be a good idea.

  • upside: all the commit related info is in the same job. reusing the same job rather than launching a new one so a tiny bit quicker (but honestly not that crucial)
  • downside: you probably need to export the commit message as environment variable into both GITHUB_ENV and GITHUB_OUTPUT but that seems fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Up to you. We can easily merge the two jobs, but IMO, 1 job per task is a more explicit approach.

@thomass-dev
thomass-dev force-pushed the ci-retrieve-commit-message-for-all-random-seed-marker branch 2 times, most recently from d4765da to 4dc5952 Compare October 23, 2025 09:10
Comment thread .github/workflows/unit-tests.yml Outdated
- name: Combine coverage reports from parallel test runners
run: bash -l build_tools/azure/combine_coverage_reports.sh
if: ${{ env.COVERAGE == 'true' }}
if: ${{ needs.retrieve-selected-tests.outputs.tests == ''}}

@lesteve lesteve Oct 23, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you still need to check ${{ env.COVERAGE }} some CI builds have COVERAGE: 'false', one reason is that measuring coverage has a significant overhead e.g. on Windows which makes the CI slower.

Right now, for simplicity I would not bother checking the selected tests. I would compute coverage and upload it, the coverage will be very low because you ran only a few tests but that's fine since coverage is not a required check.

I would go as far as saying that it's actually a feature, to remember you that you did not run the full CI but only a small number of tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Revert in 3388367.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For further reference by removing the if selected-tests is empty, the combine_coverage_reports.sh was giving an error:

No data to combine

Not sure why but fair enough, let's leave it for later ...

Comment thread .github/workflows/unit-tests.yml Resolved
Comment thread .github/workflows/unit-tests.yml Outdated
# Write selected tests to `GITHUB_OUTPUT`
with open(os.environ["GITHUB_OUTPUT"], "a") as file:
file.write(f"tests={selected_tests}\n")
env:

@lesteve lesteve Oct 23, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would move the env section before the run I find it slightly more natural, first "here are the environement variables", second "now run this script"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c65083a.

@lesteve

lesteve commented Oct 23, 2025 •

Copy link
Copy Markdown
Member

OK the all random seeds seems to be working fine on both Azure (build log) and GHA (build log)

Now pushing a normal empty commit to see if the empty selected tests case actually works 🤞. Edit: it was actually using -k '' which kind of worked to select all the tests but was a bit surprising

@lesteve lesteve left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice to see the Azure -> GHA migration progressing further and further 🙏

@lesteve
lesteve marked this pull request as ready for review October 23, 2025 14:12
@lesteve
lesteve enabled auto-merge (squash) October 23, 2025 14:12
@lesteve
lesteve disabled auto-merge October 23, 2025 14:13
@lesteve

lesteve commented Oct 23, 2025

Copy link
Copy Markdown
Member

I double-checked the [all random seeds] marker was working both on Azure and GHA. Now let's try to trigger the full CI.

@lesteve lesteve changed the title CI Set SELECTED_TESTS in unit-tests.yml to allow the use of [all random seeds] marker in GHA CI Handle [all random seeds] commit marker in GHA Oct 23, 2025
@lesteve
lesteve merged commit 081dffd into scikit-learn:main Oct 23, 2025
@lesteve

lesteve commented Oct 23, 2025

Copy link
Copy Markdown
Member

Let's merge this one thanks!

@lesteve

lesteve commented Oct 23, 2025 •

Copy link
Copy Markdown
Member

For the record main commit CI was red because [all random seeds] was in the commit message, but this is not a big deal since this is rarely the case
build log but the next run just worked fine build log

In an ideal world the commit message markers would only change behaviour on PRs.

@thomass-dev
thomass-dev deleted the ci-retrieve-commit-message-for-all-random-seed-marker branch October 23, 2025 16:07
@thomass-dev

Copy link
Copy Markdown
Contributor Author

For the record main is broken because [all random seeds] was in the commit message, but this is not a big deal since this is rarely the case build log but the next run just worked fine build log

Following PR: #32558.

rouk1 pushed a commit to rouk1/scikit-learn that referenced this pull request Nov 3, 2025
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.

2 participants