Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Feature: add code boilerplate check into circleci #813

Merged
merged 1 commit into from
Aug 21, 2019

Conversation

SataQiu
Copy link
Member

@SataQiu SataQiu commented Aug 14, 2019

Ⅰ. Describe what this PR did

Feature: add code format check into circleci

  1. add code boilerplate check as a circleci job
  2. make check-boilerplate.go always exit with 0, so we can catch the output
  3. fix gofmt check bug (ignore vendor)

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

Ⅳ. Describe how to verify it

make boilerplate-check

Ⅴ. Special notes for reviews

@@ -102,6 +112,7 @@ workflows:
ci:
jobs:
- markdownlint-misspell-shellcheck
- gocode-format-check
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add this in gocode-check-via-gometalinter-swagger.

@@ -116,14 +116,9 @@ func main() {
os.Exit(1)
}

hasErr := false
for _, filePath := range os.Args[1:] {
if err := verifyFile(filePath); err != nil {
fmt.Printf("error validating %q: %v\n", filePath, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This message should be printed in stderr, while now it is streamed to stdout, which seems to be incorrect. WDYT? @SataQiu

Copy link
Member Author

@SataQiu SataQiu Aug 14, 2019

Choose a reason for hiding this comment

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

pouchcontainer/pouchlinter:v0.2.1 has no GCC installed.
Emm, I don't know where GCC is used...
Update pouchcontainer/pouchlinter:v0.2.1 or create a new job using circleci/golang:1.12.6 ?
WDYT? @allencloud

Copy link
Collaborator

@yeya24 yeya24 Aug 14, 2019

Choose a reason for hiding this comment

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

Latest pouchcontainer/pouchlinter:v0.2.2 has installed gcc if you need it.
ref: dragonflyoss/linter#17 (comment) 😄 hope it help for you.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK! Let's bump to pouchcontainer/pouchlinter:v0.2.2. 😆

Copy link
Collaborator

Choose a reason for hiding this comment

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

But in pouchcontainer/pouchlinter:v0.2.2 we removed gometaliner. We need to update circle-ci part to migrate to golangci-lint first. So I will open a PR tonight and after that you can work on this PR. Is it ok? I will finish it ASAP.

Copy link
Member Author

@SataQiu SataQiu Aug 14, 2019

Choose a reason for hiding this comment

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

OK. Waiting for your good news. @yeya24

@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch 3 times, most recently from 35b601d to 54fc602 Compare August 14, 2019 10:24
@pouchrobot pouchrobot added size/M and removed size/S labels Aug 14, 2019
@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from 54fc602 to a39eae3 Compare August 14, 2019 10:29
@pouchrobot pouchrobot added size/S and removed size/M labels Aug 14, 2019
@@ -78,15 +77,15 @@ func checkBoilerplate(content string) error {
return fmt.Errorf("the file is missing a boilerplate")
}
if index < len(boilerplate) {
return errors.New("boilerplate has missing lines")
return fmt.Errorf("boilerplate has missing lines")
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if the change is unnecessary, since I think both are the same. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just want to clean something as I already imported fmt. :)

@@ -62,6 +62,9 @@ jobs:
command: |
make go-mod-vendor
gometalinter --disable-all --skip vendor --skip test -E deadcode ./...
- run:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need rebase this part onto the latest master branch.

@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from a39eae3 to 09fa632 Compare August 20, 2019 05:16
@pouchrobot pouchrobot added size/L and removed size/S labels Aug 20, 2019
@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from 09fa632 to 8d274e4 Compare August 20, 2019 05:18
@codecov-io
Copy link

codecov-io commented Aug 20, 2019

Codecov Report

Merging #813 into master will increase coverage by 0.02%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #813      +/-   ##
==========================================
+ Coverage   39.63%   39.66%   +0.02%     
==========================================
  Files         109      109              
  Lines        6433     6429       -4     
==========================================
  Hits         2550     2550              
+ Misses       3675     3671       -4     
  Partials      208      208
Impacted Files Coverage Δ
supernode/daemon/mgr/progress/progress_delete.go 0% <ø> (ø) ⬆️
hack/boilerplate/check-boilerplate.go 36.58% <0%> (+3.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 017c312...c8c81cb. Read the comment docs.

@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from 8d274e4 to 348a128 Compare August 20, 2019 05:26
@SataQiu
Copy link
Member Author

SataQiu commented Aug 20, 2019

@allencloud @yeya24
Considering that golanglint has checked gofmt, golint and govet, I recommend checking boilerplate separately.

@yeya24 yeya24 removed the areas/test label Aug 20, 2019
@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from d6afc5b to 348a128 Compare August 20, 2019 05:30
@yeya24
Copy link
Collaborator

yeya24 commented Aug 20, 2019

@allencloud @yeya24
Considering that golanglint has checked gofmt, golint and govet, I recommend checking boilerplate separately.

Agree with that. If you want to only add boilerplate check, could please change the PR's title? 😄

@SataQiu SataQiu changed the title Feature: add code format check into circleci Feature: add code boilerplate check into circleci Aug 20, 2019
@SataQiu
Copy link
Member Author

SataQiu commented Aug 20, 2019

Need review. @yeya24 @allencloud


check() {
# boilerplate check
echo "CHECK: boilerpalte, check code boilerplate"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sentence looks weird. Why not just use Begin to check code boilerplate here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I write Begin to check code boilerplate in Makefile. Maybe just remove this? WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, just keep one comment is OK.

hack/check.sh Outdated
@@ -10,7 +10,7 @@ cd "${curDir}/../" || return
check() {
# gofmt
echo "CHECK: gofmt, check code formats"
result=$(find . -name '*.go' -print0 | xargs -0 gofmt -s -l -d 2>/dev/null)
result=$(find . ! -path './vendor*' -name '*.go' -print0 | xargs -0 gofmt -s -l -d 2>/dev/null)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to add vendor here? @SataQiu

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an implicit bug. It does not exclude possible vendor directory. If we run make go-mod-vendor and then run make check, it will failed.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should not check vendor, Right?

Copy link
Collaborator

@yeya24 yeya24 Aug 20, 2019

Choose a reason for hiding this comment

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

Yes, but after migrating to golangci-lint we don't run make go-mod-vendor now. So I think you can remove this.

@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from a61e4a7 to fac9805 Compare August 20, 2019 15:16
@SataQiu SataQiu force-pushed the add-codecheck-2-circleci branch from fac9805 to c8c81cb Compare August 20, 2019 15:18
@allencloud
Copy link
Contributor

Generally LGTM. While I still have a question, if I am new guy to contribute to dragonfly, when I forgot to add the boilerplate, then the CI would fail, but what exactly error message the CI output would throw to me? Is the error message friendly to a new guy?

@allencloud allencloud self-assigned this Aug 20, 2019
@SataQiu
Copy link
Member Author

SataQiu commented Aug 21, 2019

Generally LGTM. While I still have a question, if I am new guy to contribute to dragonfly, when I forgot to add the boilerplate, then the CI would fail, but what exactly error message the CI output would throw to me? Is the error message friendly to a new guy?

Someting like this:

error validating "dfdaemon/config/config.go": the file is missing a boilerplate

If we have a command like make update-boilerplate, that will be great.

@allencloud
Copy link
Contributor

allencloud commented Aug 21, 2019

If we have a command like make update-boilerplate, that will be great.

No, I do not think so. I think the boilerplate should be made from the developer manually. Everyone should be aware of the copyright part and some others. If the script helps to do this, then lots of developer can escape from deep understanding the duties and obligations.

@allencloud
Copy link
Contributor

allencloud commented Aug 21, 2019

LGTM, thanks a lot for your great work.

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Aug 21, 2019
@allencloud allencloud merged commit 8e41c83 into dragonflyoss:master Aug 21, 2019
starnop pushed a commit to starnop/Dragonfly that referenced this pull request Nov 27, 2019
…leci

Feature: add code boilerplate check into circleci
inoc603 pushed a commit to inoc603/Dragonfly that referenced this pull request Dec 23, 2019
…leci

Feature: add code boilerplate check into circleci
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
areas/test kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants