Skip to content
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

Improve pre-commit UX #5320

Merged
merged 2 commits into from
Dec 10, 2024
Merged

Improve pre-commit UX #5320

merged 2 commits into from
Dec 10, 2024

Conversation

bryan-cox
Copy link
Contributor

@bryan-cox bryan-cox commented Dec 4, 2024

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
This PR improves the user experience of pre-commit by:

  • adding default stages and default install hook types to the pre-commit configuration
  • adding the stages in which certain hooks should be run
  • adding make verify and make test to the pre-push stage

Example output:

pre-commit hook run

 % pre-commit run --hook-stage pre-commit
Detect hardcoded secrets.................................................Passed
ShellCheck v0.10.0...................................(no files to check)Skipped
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
detect private key.......................................................Passed
pylint...............................................(no files to check)Skipped
Forbid binaries......................................(no files to check)Skipped

pre-push hook run

% git push -f
Run make verify-modules..................................................Passed
Run make verify-gen......................................................Passed
Run make verify-shellcheck...............................................Passed
Run make verify-conversions..............................................Passed
Run make verify-tiltfile.................................................Passed
Run make test............................................................Passed
Enumerating objects: 5, done.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #5318

Special notes for your reviewer:

  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

NONE

/assign @nawazkh

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Dec 4, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 4, 2024
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.52%. Comparing base (1275143) to head (b33199c).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5320   +/-   ##
=======================================
  Coverage   52.52%   52.52%           
=======================================
  Files         272      272           
  Lines       29422    29422           
=======================================
  Hits        15455    15455           
  Misses      13168    13168           
  Partials      799      799           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
This commit adds default stages and default install hook types to the
pre-commit configuration. In addition, it adds the stages in which
certain hooks should be run.

Signed-off-by: Bryan Cox <[email protected]>
Comment on lines 35 to 41
- repo: local
hooks:
- id: make-verify
name: Run make verify
entry: make verify
language: system
stages: [pre-push]
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we can add a reference to Makefile's verify target in here or put up a comment?
A disclaimer saying that make verify is going to invoke a bunch of targets like
verify-boilerplate verify-modules verify-gen verify-shellcheck verify-conversions verify-tiltfile verify-codespell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Great! Let's add some text in here, as a disclaimer, make verify will run verify-boilerplate verify-modules verify-gen verify-shellcheck verify-conversions verify-tiltfile verify-codespell all these targets.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the churn.
I see that boilerplate check is already run as a separate hook up above.
Do you think it would be beneficial to run these verify targets individually as separate hooks and drop redundant hooks like boilerplate and spellcheck ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see merit in either approach. Though I would lean to running the targets individually because then you can see them running one by one in a terminal rather than just one block you're waiting to finish on. Which option would you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

Running them individually as separate hooks at pre-push stage sounds great to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR is updated. I think it looks better with each one -

% git push -f
Run make verify-modules..................................................Passed
Run make verify-gen......................................................Passed
Run make verify-shellcheck...............................................Passed
Run make verify-conversions..............................................Passed
Run make verify-tiltfile.................................................Passed
Run make test............................................................Passed
Enumerating objects: 5, done.
...

FWIW, the verify-gen took a similar amount of time as test so maybe test doesn't need broken up? 🤷🏻‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for pointing this out.
Both verify-gen and test seem to be running generate as a pre-req.

So maybe we don't break test target for backwards compatibility in CI and replace make test in pre-commit config with make go-test-race.
We can follow this up in another PR, non blocking comment.

Comment on lines 42 to 66
- repo: local
hooks:
- id: make-test
name: Run make test
entry: make test
language: system
stages: [pre-push]
Copy link
Member

Choose a reason for hiding this comment

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

Same thought here. make test atm seems to be running generate as well. Ref:

test: generate go-test-race ## Run "generate" and "go-test-race" rules.

In my experience, make generate takes a lot of time to finish.

  • I wonder if we can drop generate as a dependency? Or
  • Maybe come up with a new make target that runs UT exclusively ? i.e. runs make go-test-race. So essentially we run make go-test-race in this hook. Although I have not tested the side affects of running make go-test-race by itself.

However, this comment can be a followed up another issue-PR.

This commit adds the same checks run in `make verify` without
duplicating any previous hook runs in pre-commit to the pre-commit
configuration. In addition, this commit adds `make test` to the pre-push
 stage of the pre-commit configuration. This will ensure `verify` and
`test` are successfully passing before the commit is pushed. This will
help reduce time and test resources by preventing `verify` and `test`
from failing on the pull request in GitHub.

Signed-off-by: Bryan Cox <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 6, 2024
name: Run make verify-shellcheck
entry: make verify-shellcheck
language: system
stages: [ pre-push ]
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if [ pre-push ] is any different to [pre-push] (extra space padding being added to pre-push string).

Could please paste sample output of using this .pre-commit.config in the PR description or as a comment?


This looks great to me btw!
/lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added some example output to the PR description

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 8, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: df5e05410858492f9c3645ae91eeb71eb67d9e8b

@nawazkh
Copy link
Member

nawazkh commented Dec 8, 2024

You might wanna see this too, Matt :)
/cc @mboersma

Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mboersma

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2024
@k8s-ci-robot k8s-ci-robot merged commit 627c0fb into kubernetes-sigs:main Dec 10, 2024
23 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve Pre-commit UX
4 participants