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 code checking #131

Merged
merged 3 commits into from Jun 5, 2019
Merged

Conversation

phoracek
Copy link
Member

@phoracek phoracek commented Jun 2, 2019

Let's automate more code validation. And reorganize Makefile targets a little.

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L labels Jun 2, 2019
@phoracek phoracek changed the title WIP Improve code checking Improve code checking Jun 2, 2019
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 2, 2019
@phoracek
Copy link
Member Author

phoracek commented Jun 2, 2019

@booxter @SchSeba @qinqon please take a look

@phoracek phoracek self-assigned this Jun 2, 2019
@phoracek phoracek force-pushed the improve_code_checking branch 3 times, most recently from 22fdf59 to 37b5e21 Compare June 2, 2019 13:11
Copy link
Contributor

@SchSeba SchSeba left a comment

Choose a reason for hiding this comment

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

overall looks good just two small nits

.travis.yml Outdated Show resolved Hide resolved
.travis.yml Show resolved Hide resolved
SchSeba
SchSeba previously approved these changes Jun 3, 2019
Copy link
Contributor

@SchSeba SchSeba left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

To be sure to run static code checks and code generations tools before calling docker build we can track source files with $(wildcard..) and generate little dummy files with the target name with touch $@ this way we ensure that we call docker build with perfect code and without taking much time at noop.

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
@phoracek phoracek force-pushed the improve_code_checking branch 2 times, most recently from c4d88c4 to c632efe Compare June 3, 2019 15:36
@phoracek phoracek force-pushed the improve_code_checking branch 3 times, most recently from 8c2db6e to 0203acf Compare June 3, 2019 15:54
qinqon
qinqon previously approved these changes Jun 3, 2019
Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

LGTM, we have to be careful with deletes though.

Makefile Outdated Show resolved Hide resolved
@phoracek phoracek force-pushed the improve_code_checking branch 2 times, most recently from fe7bb97 to de041b2 Compare June 3, 2019 16:07
Signed-off-by: Petr Horacek <phoracek@redhat.com>
@phoracek phoracek force-pushed the improve_code_checking branch 5 times, most recently from db0341a to d33880f Compare June 3, 2019 17:15
booxter
booxter previously approved these changes Jun 4, 2019
Copy link
Contributor

@booxter booxter left a comment

Choose a reason for hiding this comment

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

my comments are largely nits / nice to haves so not blocking the merge here.

README.md Outdated Show resolved Hide resolved
hack/verify-codegen.sh Outdated Show resolved Hide resolved
hack/whitespace.sh Outdated Show resolved Hide resolved
Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

Found how to fix rebuild on deletes, let's just add that and merge.

Makefile Outdated Show resolved Hide resolved
@phoracek
Copy link
Member Author

phoracek commented Jun 4, 2019

@qinqon sorry man, but I also need all_sources (exluding vendor/), and I'm not able to pull that off using beautiful Makefile tools. Tried following, but it doesn't filter-out anything:

vendor_sources := $(call rwildcard,vendor/,*)
all_sources := $(filter-out $(vendor_sources), $(call rwildcard,.)) .

We can reiterate on that part.

@phoracek
Copy link
Member Author

phoracek commented Jun 4, 2019

@booxter @qinqon thanks a lot for the previous review. Should be fixed, could you give it another iteration?

@phoracek phoracek mentioned this pull request Jun 4, 2019
booxter
booxter previously approved these changes Jun 5, 2019
Copy link
Collaborator

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

Finding all files is loaded everytime we call make... maybe is time to move to pre-commit.

Also you have to replace find by the rwildcard

Makefile Outdated

# Gather needed source files and directories to create target dependencies
all_sources := $(shell git ls-files -- ':!vendor/')
cmd_sources := $(shell find ./cmd/ -type f -name '*.go')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have to use the rwildcard make function we just created and also add the directory to detect deletes.

# Gather needed source files and directories to create target dependencies
cmd_sources := $(call rwildcard,cmd/,*.go) cmd/
pkg_sources := $(call rwildcard,pkg/,*.go) pkg/
apis_sources := $(call rwildcard,pkg/apis/,*.go) pkg/apis/

Copy link
Member Author

Choose a reason for hiding this comment

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

Makefile Outdated
pkg_sources := $(shell find ./pkg/ -type f -name '*.go')
apis_sources := $(shell find ./pkg/apis/ -type f -name '*.go')

petr:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have to be good to be a make target :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

:(

Copy link
Contributor

Choose a reason for hiding this comment

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

Petr deserves it

Makefile Outdated
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

# Gather needed source files and directories to create target dependencies
all_sources := $(shell git ls-files -- ':!vendor/')
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have to be careful making this depend on git, if we use at build we are not going to be able to build from tarball for example.

This sanity check stuff is starting to blow out of proportion, at openstack we use pre-commit and there some pre-commit hooks for golang

Copy link
Member Author

Choose a reason for hiding this comment

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

make whitespace-check  0.09s user 0.02s system 97% cpu 0.114 total

@phoracek phoracek force-pushed the improve_code_checking branch 2 times, most recently from 793e629 to ef922a0 Compare June 5, 2019 11:42
qinqon
qinqon previously approved these changes Jun 5, 2019
Use goimports to check code:
goimports checks what gofmt does plus it keeps imports in specific
order. In this patch we:
- replace gofmt with goimports
- add code format checking to travis
- reorganize Makefile a little bit
- remove make generate-manifests from README.md since it is not needed
  during the development process
- add Makefile target for operator-sdk build k8s

Add whitespace check and auto-formatting:
I hate trailing whitespaces. This patch adds automated check detecting
any and Makefile target removing them.

Add codegen validation:
Add a check validating that generated code is up to date. This would
fail on travis in case a contributor forget to run `make generate-api`.

ship and goimports operator-sdk in vendor/:
In order to make sure everyone uses the same version of operator-sdk
producing the same code, let's keep operator-sdk in vendoring. The
same for goimports.

Signed-off-by: Petr Horacek <phoracek@redhat.com>
@phoracek
Copy link
Member Author

phoracek commented Jun 5, 2019

ci test please

Copy link
Contributor

@booxter booxter left a comment

Choose a reason for hiding this comment

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

I love approving PRs with 1.5 mln LOC.

@phoracek phoracek merged commit e0d21c5 into kubevirt:master Jun 5, 2019
@phoracek
Copy link
Member Author

phoracek commented Jun 5, 2019

Feels good, thanks guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants