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

Commit

Permalink
add boilerplate-check into circleci
Browse files Browse the repository at this point in the history
Signed-off-by: SataQiu <[email protected]>
  • Loading branch information
SataQiu committed Aug 20, 2019
1 parent 017c312 commit c8c81cb
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ jobs:
name: use golangci-lint to check gocode of this project.
command: |
make golangci-lint
- run:
name: boilerplate check
command: |
make boilerplate-check
unit-test-golang:
docker:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@ integration-test:
@go test ./test
.PHONY: integration-test

check:
check: boilerplate-check
@echo "Begin to check code formats."
./hack/check.sh
@echo "Begin to check dockerd whether is startup"
./hack/check-docker.sh
.PHONY: check

boilerplate-check:
@echo "Begin to check code boilerplate."
./hack/boilerplate-check.sh
.PHONY: boilerplate-check

go-mod-tidy:
@echo "Begin to tidy up go.mod and go.sum"
@go mod tidy
Expand Down
18 changes: 18 additions & 0 deletions hack/boilerplate-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -o nounset
set -o errexit
set -o pipefail

curDir=$(cd "$(dirname "$0")" && pwd)
cd "${curDir}/../" || return

check() {
result=$(git ls-files | xargs go run ./hack/boilerplate/check-boilerplate.go 2>&1)
if [[ ${#result} -gt 0 ]]; then
echo "${result}"
return 1
fi
}

check
14 changes: 4 additions & 10 deletions hack/boilerplate/check-boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package main

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -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")
}
return nil
}

// verifyFile verifies if a file contains the boilerplate
func verifyFile(filePath string) error {
if len(filePath) == 0 {
return errors.New("empty file name")
return fmt.Errorf("empty file name")
}

// check file extension is go
Expand All @@ -112,18 +111,13 @@ func verifyFile(filePath string) error {

func main() {
if len(os.Args) < 2 {
fmt.Println("usage: go run check-boilerplate.go <path-to-file> <path-to-file> ...")
fmt.Fprintln(os.Stderr, "usage: go run check-boilerplate.go <path-to-file> <path-to-file> ...")
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)
hasErr = true
fmt.Fprintf(os.Stderr, "error validating %q: %v\n", filePath, err)
}
}
if hasErr {
os.Exit(1)
}
}
8 changes: 0 additions & 8 deletions hack/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ check() {
echo "CHECK: go vet, check code syntax"
packages=$(go list ./... | sed 's/^_//')
echo "${packages}" | xargs go vet 2>&1

# boilerplate check
echo "CHECK: boilerpalte, check code boilerplate"
result=$(git ls-files | xargs go run ./hack/boilerplate/check-boilerplate.go)
if [[ ${#result} -gt 0 ]]; then
echo "${result}"
return 1
fi
}

check
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/gc/gc_dfget_task.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gc

import (
Expand Down
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/gc/gc_manager.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gc

import (
Expand Down
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/gc/gc_peer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gc

import (
Expand Down
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/gc/gc_task.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gc

import (
Expand Down
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/gc_mgr.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package mgr

import (
Expand Down
16 changes: 16 additions & 0 deletions supernode/daemon/mgr/progress/progress_delete.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The Dragonfly Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package progress

import (
Expand Down

0 comments on commit c8c81cb

Please sign in to comment.