Skip to content

CI Add label when linting fails - #32751

Merged
lesteve merged 7 commits into
scikit-learn:mainfrom
FrancoisPgm:linter_bot_label
Nov 24, 2025
Merged

lesteve merged 7 commits into
scikit-learn:mainfrom
FrancoisPgm:linter_bot_label

Conversation

@FrancoisPgm

Copy link
Copy Markdown
Member

Reference Issues/PRs

What does this implement/fix? Explain your changes.

The "Bot linter comment" action now adds a "CI : lniter fails" label to a PR if the linter fails, or removes it if the linter succeeds.

Any other comments?

This change requires a label with the name "CI : linter fails" (or any relevant name) to be created.

@github-actions

github-actions Bot commented Nov 20, 2025 •

Copy link
Copy Markdown

✔️ Linting Passed

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

Generated for commit: 0673d39. Link to the linter CI: here

@FrancoisPgm FrancoisPgm changed the title [CI] Make the linter comment bot add or remove a "CI : linter fails" label CI Make the linter comment bot add or remove a "CI : linter fails" label Nov 20, 2025

@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.

It's a bit weird that the logic is based on the comment content. I guess it should be based on the CI status instead, i.e. failure/success?

Having said this, I am not familiar with this script, so it's just a bit of a random comment.

@FrancoisPgm

Copy link
Copy Markdown
Member Author

I took inspiration on the get_message function which looks at the content of the log file of the linter to check for the status and create the comment.

@FrancoisPgm

Copy link
Copy Markdown
Member Author

Here is a PR on my fork where I tested it : FrancoisPgm#3

@FrancoisPgm

Copy link
Copy Markdown
Member Author

It's a bit weird that the logic is based on the comment content. I guess it should be based on the CI status instead, i.e. failure/success?

I am not sure how to check for another workflow status, but anyway the Linter workflow appears as successful even when the linting fails, I think it might be so that the artifacts are uploaded anyway after the linting failed so they can be retrieved by the commenter bot.

@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.

Thanks, I tweaked the label name and created the associated label.

I think we can always change our mind afterwards, let's merge it and try it.

What could possibly go wrong on a Friday afternoon 😅

@lesteve

lesteve commented Nov 21, 2025 •

Copy link
Copy Markdown
Member

I am not sure how to check for another workflow status, but anyway the Linter workflow appears as successful even when the linting fails, I think it might be so that the artifacts are uploaded anyway after the linting failed so they can be retrieved by the commenter bot.

Probably? I guess looking at the content of the log file is the most convenient thing you have.

In an ideal world we would rewrite this script with PyGithub because it looks like there are many things that are a bit cumbersome with REST API calls.

One downside is that we would be relying on a dependency, and you never know things can break.

We are already using PyGithub for others parts of the CI, and so far no breaking change has bitten us (I think).

@lesteve

lesteve commented Nov 21, 2025 •

Copy link
Copy Markdown
Member

also cc @adrinjalali who was interested by the "CI:Linter failure" label IIRC.

@lesteve

lesteve commented Nov 21, 2025

Copy link
Copy Markdown
Member

What could possibly go wrong on a Friday afternoon 😅

OK I tried to be bold, but I changed my mind after 5 minutes. I would rather merge this on Monday to be around in case there is an unexpected side-effect 😅

@lesteve lesteve changed the title CI Make the linter comment bot add or remove a "CI : linter fails" label CI Make the linter comment bot add a label Nov 21, 2025
@lesteve lesteve changed the title CI Make the linter comment bot add a label CI Add label when linting fails Nov 21, 2025
@lesteve

lesteve commented Nov 24, 2025

Copy link
Copy Markdown
Member

All right, let's merge this and see what happens!

@lesteve
lesteve merged commit a34fe7d into scikit-learn:main Nov 24, 2025
@lesteve

lesteve commented Nov 24, 2025 •

Copy link
Copy Markdown
Member

I tested this in #32745 (comment) and it seems to work fine 🎉. The label was added on linter failure and then removed when linting passes.

image

@StefanieSenger

StefanieSenger commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

This is slightly off topic, (but better then creating a new issue for that.)

Now that we communicate pre-commit as a requirement in the developer docs (#32664), hopefully linting issues will become less frequent and we don't need to show the comment if the linting passes. If we remove it there is no comment to check for and this new addition to the code needs to get adapted to actually check for the CI status instead for the comment.

I think only posting the comment if the linting is broken is also easier for new contributors to digest, since it will be posted right below the commit that made the linter unhappy instead of outside of the timeline (the update in the old comment can be missed).

What do people think about removing the comment if the linter passes? I think we had briefly talked about it on the scientific python summit.

@FrancoisPgm

Copy link
Copy Markdown
Member Author

I like the idea of not having a comment when everything is ok, a "no news good news" approach which minimizes noise.
I am just wandering in the case where the linting is broken and then fixed, if the comment should be deleted or just updated by the bot. IMO deleting would be cleaner but keeping a readable history could be preferable.

@lesteve

lesteve commented Nov 27, 2025 •

Copy link
Copy Markdown
Member

I was kind of thinking the same thing lately that we could only have a comment when linting fails and delete the comment when linting succeeds. I don't think we care too much about keeping the comment history.

The thing I would suggest:

  • first rewrite the build_tools/get_comment.py with PyGithub: it would simplify a lot of the logic we do by hand. Probably a LLM would be able to give you a reasonable head start but cleaning up the script would be a good idea 😉.
  • then investigate the strategy of deleting the comment when linting fails

Some reasons why I slighly prefer to delete the comment:

  • the bot linting comment makes it a tiny bit harder to see PRs without replies. Having said this I just learned that you can filter by number of comments, not sure since when, I completely missed this somehow e.g. search for PRs with less than 2 comments ...
  • I am not a big fan of bot comments in general (but different people have different opinions). For example, I prefer a CI status than a bot comment when possible, less notifications and less visual noise in the issue (it's OK when you have a single bot comment but when you have many it's a bit of a pain).

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.

3 participants