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

[v2] Add pre-commit and CI static checks #1025

Merged
merged 7 commits into from
Aug 26, 2020

Conversation

turbaszek
Copy link
Contributor

@turbaszek turbaszek commented Aug 22, 2020

Code quality is important, especially in an open source project where the code will be maintained for a long time and by multiple people. So I would like to suggest using https://pre-commit.com framework to automate a lot of stuff and assure that our code is nice.

It plays nicely with Github action and allows a plethora of checks (building TOC, license insert, liniting etc) and gives possibility to build custom ones. For example here's configuration from Apache Airflow:
https://github.com/apache/airflow/blob/master/.pre-commit-config.yaml

Checklist

@turbaszek
Copy link
Contributor Author

There are quite a few go-lint errors that I'm happy to fix if we agree to proceed with this change 😃

@turbaszek turbaszek marked this pull request as ready for review August 22, 2020 20:15
Comment on lines 9 to 29
exclude: |
(?x)(
.*zz_generated.*|
^pkg/apis/keda/v1alpha1/triggerauthentication_types\.go$|
^pkg/handler/hashicorpvault_handler\.go$|
^pkg/scalers/azure/azure_aad_podidentity\.go$|
^pkg/scalers/azure/azure_eventhub\.go$|
^pkg/scalers/azure/azure_monitor\.go$|
^pkg/scalers/azure/azure_storage\.go$|
^pkg/scalers/azure_eventhub_scaler\.go$|
^pkg/scalers/azure_queue_scaler\.go$|
^pkg/scalers/azure_servicebus_scaler\.go$|
^pkg/scalers/cron_scaler\.go$|
^pkg/scalers/kafka_scram_client\.go$|
^pkg/scalers/liiklus_scaler\.go$|
^pkg/scalers/postgresql_scaler\.go$|
^pkg/scalers/prometheus\.go$|
^pkg/scalers/rabbitmq_scaler\.go$|
^pkg/scalers/scaler\.go$|
^version/version\.go$
)
Copy link
Contributor Author

@turbaszek turbaszek Aug 22, 2020

Choose a reason for hiding this comment

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

Those can be fixed in follow up PRs and make good candidates for good-first-issues (Hacktober is coming) 😄

Copy link
Member

Choose a reason for hiding this comment

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

If this gets merged, please don't forget to open issues for these.

Copy link
Member

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

This looks OK to me, thanks!

Just make sure to target v2 instead of master so that @zroubalik doesn't have to plow through all of these.

Just a tip, let's discuss this in an issue first in the future because if we didn't like this then you would've wasted a ton of work

Comment on lines 9 to 29
exclude: |
(?x)(
.*zz_generated.*|
^pkg/apis/keda/v1alpha1/triggerauthentication_types\.go$|
^pkg/handler/hashicorpvault_handler\.go$|
^pkg/scalers/azure/azure_aad_podidentity\.go$|
^pkg/scalers/azure/azure_eventhub\.go$|
^pkg/scalers/azure/azure_monitor\.go$|
^pkg/scalers/azure/azure_storage\.go$|
^pkg/scalers/azure_eventhub_scaler\.go$|
^pkg/scalers/azure_queue_scaler\.go$|
^pkg/scalers/azure_servicebus_scaler\.go$|
^pkg/scalers/cron_scaler\.go$|
^pkg/scalers/kafka_scram_client\.go$|
^pkg/scalers/liiklus_scaler\.go$|
^pkg/scalers/postgresql_scaler\.go$|
^pkg/scalers/prometheus\.go$|
^pkg/scalers/rabbitmq_scaler\.go$|
^pkg/scalers/scaler\.go$|
^version/version\.go$
)
Copy link
Member

Choose a reason for hiding this comment

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

If this gets merged, please don't forget to open issues for these.

.github/workflows/static-checks.yml Outdated Show resolved Hide resolved
@turbaszek
Copy link
Contributor Author

@tomkerkhove thanks for the review! Regarding:

Just a tip, let's discuss this in an issue first in the future because if we didn't like this then you would've wasted a ton of work

I just copy pasted pre-commit config from my other go repo so not a lot of work 😉

@turbaszek
Copy link
Contributor Author

turbaszek commented Aug 24, 2020

Oh, DCO doesn't accept PR added from GitHub review? :<

@turbaszek turbaszek changed the base branch from master to v2 August 24, 2020 08:34
@turbaszek turbaszek force-pushed the add-pre-commits-ci branch 2 times, most recently from 5990e57 to 8010885 Compare August 24, 2020 08:47
@turbaszek
Copy link
Contributor Author

@zroubalik I've rebased this change onto v2 👍

@turbaszek turbaszek force-pushed the add-pre-commits-ci branch 2 times, most recently from 25595ec to 25f8027 Compare August 24, 2020 08:52
@zroubalik zroubalik changed the title Add pre-commit and CI static checks [v2] Add pre-commit and CI static checks Aug 24, 2020
@turbaszek turbaszek mentioned this pull request Aug 24, 2020
8 tasks
@mik-laj
Copy link

mik-laj commented Aug 24, 2020

❤️ 😻 ❤️

CONTRIBUTING.md Outdated Show resolved Hide resolved
Copy link
Member

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

LGTM but I'll leave it up to @zroubalik to give the sign-off

@@ -4,6 +4,19 @@ Thanks for helping make KEDA better 😍.

There are many areas we can use contributions - ranging from code, documentation, feature proposals, issue triage, samples, and content creation.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
Copy link
Member

Choose a reason for hiding this comment

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

That's great, but how does this work? Should add some docs on this :)

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 would say that's enough to google doctoc to find out more information. Also not sure where to put such docs

Copy link

Choose a reason for hiding this comment

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

Yeah. And wit pre-commits you basically do not have to worry about it - just install pre-commit and you forget about it..

Copy link
Member

Choose a reason for hiding this comment

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

That's a bit of an odd argument as that would mean we don't have to doc the pre-commit thingy but it's ok.

Yeah. And wit pre-commits you basically do not have to worry about it - just install pre-commit and you forget about it..

We tend to make it easy for folks to contribute so you cannot assume everybody has pre-commit installed, that's why we have a CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We tend to make it easy for folks to contribute so you cannot assume everybody has pre-commit installed, that's why we have a CI.

As we have totally lightweight pre-commit setup we should probably encourage people to use them. It's good to teach people how to automate stuff and focus on the most important things like the code itself and documentation. However, that's only my personal opinion.

Copy link
Member

Choose a reason for hiding this comment

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

That's definitely the case and I agree, but we can't expect everyone to use it.

Copy link

Choose a reason for hiding this comment

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

We also have it integrated on the CI, so if someone does not use pre-commit locally, they will get a readable diff on the CI that will show what changes should be made.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that was my point on #1025 (comment) indeed

Copy link

@potiuk potiuk Aug 25, 2020

Choose a reason for hiding this comment

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

Yeah. Pre-commits are working like a charm on Apache Airflow for > 1.5 year now and we have plenty of pre-commits running/ You can see it working here for example: https://github.com/apache/airflow/runs/1026196376?check_suite_focus=true#step:7:108 - it integrates very well with CI. you simply run pre-commit run --all-files in the CI and you get the very same checks executed in CI as locally.

And as @mik-laj mentioned - with --show-diff-on-failure flag it will even show you what modification would be made if you run pre-commit locally. In case it fails in CI it will even tell you what to do 'pip install pre-commit' and then pre-commit run <id of pre-commit that failed>. But you still can fix it manually if you prefer (though a lot of pre-commit checks can fix things for you automatically (like end-of-file checking, sorting import in python etc.) and then the only thing you have to do you have to commit modified files. And you have literally hundreds of hooks that you can start using.

So you do not have to even install it as pre-commit (though it is super-easy pre-commit install will do the job after installit it with pip. The nice thing about it is that you simply forget about it once you install - it will automatically run all the precommits that were added by others since and you will actually fix the problems even before others see them.

I do not see any drawbacks of using pre-commit to be honest if your project's goal is to keep some consistency, it's the perfect tool for the job IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

Don't get me wrong, I'm not saying it's a bad thing or so; I was just saying that it's fine and the CI will cover it but we shouldn't force people to use it.

I'm not saying you are, it was just a general remark :) This escalated quickly.

CONTRIBUTING.md Outdated Show resolved Hide resolved
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ahmelsayed ahmelsayed left a comment

Choose a reason for hiding this comment

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

change looks good to me. I'm assuming the CI pre-commit will fail if something needs to be fixed, right? I haven't used pre-commit before but looks neat.

Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
@turbaszek
Copy link
Contributor Author

I'm assuming the CI pre-commit will fail if something needs to be fixed, right? I haven't used pre-commit before but looks neat.

That's right! For example:

Check if scalers are sorted in scaler_handler.go............................Failed
hookid: sort-scalers

Scalers are not sorted alphabetical in pkg/scaling/scale_handler.go

Most of pre-commit hooks we use apply the changes automatically during git commit (remove white spaces, go-fmt, go-lint) so not to much to do for developers

@turbaszek
Copy link
Contributor Author

@tomkerkhove @zroubalik are we good to go?

Copy link
Member

@tomkerkhove tomkerkhove left a comment

Choose a reason for hiding this comment

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

LGTM, just one more change.

@@ -4,6 +4,19 @@ Thanks for helping make KEDA better 😍.

There are many areas we can use contributions - ranging from code, documentation, feature proposals, issue triage, samples, and content creation.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
Copy link
Member

Choose a reason for hiding this comment

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

Don't get me wrong, I'm not saying it's a bad thing or so; I was just saying that it's fine and the CI will cover it but we shouldn't force people to use it.

I'm not saying you are, it was just a general remark :) This escalated quickly.

CONTRIBUTING.md Outdated Show resolved Hide resolved
Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM, just minor remark on "enforcing" pre-commit. Thanks for the contribution

CONTRIBUTING.md Outdated Show resolved Hide resolved
Signed-off-by: Tomek Urbaszek <tomasz.urbaszek@polidea.com>
Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM

@tomkerkhove tomkerkhove merged commit 02f6da7 into kedacore:v2 Aug 26, 2020
@mik-laj
Copy link

mik-laj commented Aug 26, 2020

Tomek, great work! Thanks a lot! 🎉

@turbaszek
Copy link
Contributor Author

Thanks all! 🚀

@potiuk
Copy link

potiuk commented Aug 26, 2020

❤️

@kaxil
Copy link

kaxil commented Aug 26, 2020

<3

SpiritZhou pushed a commit to SpiritZhou/keda that referenced this pull request Jul 18, 2023
Signed-off-by: Neelanjan Manna <neelanjan.manna@harness.io>

Signed-off-by: Neelanjan Manna <neelanjan.manna@harness.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants