ci: add black + flake8 lint check workflow#2215
Open
genisis0x wants to merge 1 commit into
Open
Conversation
Fixes microsoft#2060. Adds a `Lint check` GitHub Actions workflow that runs the existing `make black` and `make flake8` targets on every push to `main` and every pull request. PRs surface formatting and style regressions at review time instead of relying on contributors to remember to run the local Makefile targets first. Intentional choices: - Only `black` and `flake8` are enforced in this initial workflow. `make lint` also chains `pylint`, `mypy` and `nbqa`, which have a larger surface and historically carry warnings the team has left intentionally unaddressed (see the long disable-lists in the Makefile comment). Keeping the CI signal binary on the two strict tools means PRs land green or red without a noisy yellow channel; the heavier checks can be folded in via follow-up if maintainers want them. - Check-only, not auto-fix. The issue's sample workflow pushed generated fixup commits back to the PR branch, which requires `pull_request_target` and `contents: write`. That combination runs with repo-write secrets in the context of an external fork's code and is the standard fork-PR escalation vector. A read-only check gives the same enforcement benefit with no fork-PR security tradeoff; contributors run `make black` / `make flake8` locally to fix issues. Pinned to a single Python (3.10, middle of the supported range from `test_qlib_from_source.yml`) so the lint job stays fast and doesn't re-run identical lint over the full test matrix.
Author
|
Read through the CLA — all good. @microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2060.
Adds a `Lint check` GitHub Actions workflow that runs the existing `make black` and `make flake8` targets on every push to `main` and every pull request. PRs surface formatting and style regressions at review time instead of relying on contributors to remember to run the local Makefile targets first.
Confirmed locally that both targets are clean against current `main` (`231 files would be left unchanged` for black, no output for flake8), so the workflow will be green on day one.
Why this deviates from the issue's sample
The issue's sample workflow pushed auto-fix commits back to the PR branch. I intentionally did not include that for one reason:
A read-only check gives the same lint-enforcement benefit with no fork-PR security tradeoff; contributors run `make black` / `make flake8` locally to fix issues. Happy to add the auto-fix variant in a separate workflow guarded by `workflow_dispatch` or `pull_request` (not `_target`) if maintainers prefer that direction.
Why only black + flake8, not all of `make lint`
`make lint` chains `black`, `pylint`, `flake8`, `mypy` and `nbqa`. The Makefile shows long disable-lists for pylint and mypy carrying historical warnings the team has left intentionally unaddressed. Folding those into a hard gate would either fail the workflow on every PR or require maintainers to first burn down the backlog. Keeping the initial CI binary on the two strict tools means PRs land green or red without a noisy yellow channel; the heavier checks can be folded in via follow-up once maintainers decide what threshold they want there.
Files
Validation
```
$ make black
black . -l 120 --check --diff --exclude qlib/_version.py
All done! ✨ 🍰 ✨
231 files would be left unchanged.
$ make flake8
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 --per-file-ignores="init.py:F401,F403" qlib
(no output)
```
The workflow uses Python 3.10 — middle of the supported range from `test_qlib_from_source.yml` — so the lint job stays fast and doesn't re-run identical lint over the full test matrix.
Fixes #2060