CI(ruff): Fine tune posting Ruff suggestions #3978
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I overlooked the situation where some ruff errors can and cannot be fixed in the same pass. The exit code won’t be 0 if not all files were fixed. This prevented to reach the step where the diff was stored as an artifact to upload suggestions, to post.
So instead of setting the ruff step with
continue-on-errors: true
, which would have shown the step as gray (passing), even when rules without fixes are failing, I set the condition toif: ${{ !cancelled() }}
as mentioned in the docs for always() https://docs.github.com/en/actions/learn-github-actions/expressions#alwaysI also spotted a copy-paste typo in the post-pr-reviews workflow, that I had already fixed on another branch but forgot to apply on the one that ended up being a PR.
Finally, I reconsidered my initial position on only applying the safe fixes. Since it is not directly committing, only posting suggestions, it makes sense to show suggestions on what will still remain an error, but without the suggested fixes. Unlike Black, we might need to think a bit about the fixes anyways, when available. Following that thought, I don’t think it’s appropriate in pre-commit to make unsafe fixes on behalf of the user, without any review.