build: Simplify test/lint related targets

Signed-off-by: Stanislav Bogatyrev <stanislav@nspcc.ru>
This commit is contained in:
Stanislav Bogatyrev 2020-08-01 00:01:10 +03:00 committed by Stanislav Bogatyrev
parent c876e89efb
commit d83f2e8b47
2 changed files with 47 additions and 15 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@ cmd/test
testfile testfile
.neofs-cli.yml .neofs-cli.yml
.cache

View file

@ -15,7 +15,7 @@ CMDS = neofs-node neofs-ir
CMS = $(addprefix $(BIN)/, $(CMDS)) CMS = $(addprefix $(BIN)/, $(CMDS))
BINS = $(addprefix $(BIN)/, $(CMDS)) BINS = $(addprefix $(BIN)/, $(CMDS))
.PHONY: help dep clean fmt .PHONY: help all dep clean fmts fmt imports test lint docker/lint
# To build a specific binary, use it's name prefix with bin/ as a target # To build a specific binary, use it's name prefix with bin/ as a target
# For example `make bin/neofs-node` will build only storage node binary # For example `make bin/neofs-node` will build only storage node binary
@ -24,9 +24,9 @@ all: $(DIRS) $(BINS)
$(BINS): $(DIRS) dep $(BINS): $(DIRS) dep
@echo "⇒ Build $@" @echo "⇒ Build $@"
GOGC=off \
CGO_ENABLED=0 \ CGO_ENABLED=0 \
go build -v -mod=vendor -trimpath \ GO111MODULE=on \
go build -v -trimpath \
-ldflags "-X ${REPO}/misc.Version=$(VERSION) -X ${REPO}/misc.Build=${BUILD}" \ -ldflags "-X ${REPO}/misc.Version=$(VERSION) -X ${REPO}/misc.Build=${BUILD}" \
-o $@ ./cmd/$(notdir $@) -o $@ ./cmd/$(notdir $@)
@ -36,16 +36,21 @@ $(DIRS):
# Pull go dependencies # Pull go dependencies
dep: dep:
@printf "⇒ Ensure vendor: " @printf "⇒ Tidy requirements : "
@go mod tidy -v && echo OK || (echo fail && exit 2) CGO_ENABLED=0 \
GO111MODULE=on \
go mod tidy -v && echo OK
@printf "⇒ Download requirements: " @printf "⇒ Download requirements: "
@go mod download && echo OK || (echo fail && exit 2) CGO_ENABLED=0 \
@printf "⇒ Store vendor locally: " GO111MODULE=on \
@go mod vendor && echo OK || (echo fail && exit 2) go mod download && echo OK
@printf "⇒ Install test requirements: "
CGO_ENABLED=0 \
GO111MODULE=on \
go test -i ./... && echo OK
# Regenerate proto files: # Regenerate proto files:
protoc: protoc:
@GOPRIVATE=github.com/nspcc-dev go mod tidy -v
@GOPRIVATE=github.com/nspcc-dev go mod vendor @GOPRIVATE=github.com/nspcc-dev go mod vendor
# Install specific version for gogo-proto # Install specific version for gogo-proto
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/gogo/protobuf | xargs go get -v @go list -f '{{.Path}}/...@{{.Version}}' -m github.com/gogo/protobuf | xargs go get -v
@ -58,6 +63,7 @@ protoc:
--proto_path=.:./vendor:./vendor/github.com/nspcc-dev/neofs-api-go:/usr/local/include \ --proto_path=.:./vendor:./vendor/github.com/nspcc-dev/neofs-api-go:/usr/local/include \
--gofast_out=plugins=grpc,paths=source_relative:. $$f; \ --gofast_out=plugins=grpc,paths=source_relative:. $$f; \
done done
rm -rf vendor
# Build NeoFS Storage Node docker image # Build NeoFS Storage Node docker image
image-storage: image-storage:
@ -65,6 +71,7 @@ image-storage:
@docker build \ @docker build \
--build-arg REPO=$(REPO) \ --build-arg REPO=$(REPO) \
--build-arg VERSION=$(VERSION) \ --build-arg VERSION=$(VERSION) \
--rm \
-f Dockerfile \ -f Dockerfile \
-t $(HUB_IMAGE)-storage:$(HUB_TAG) . -t $(HUB_IMAGE)-storage:$(HUB_TAG) .
@ -74,19 +81,42 @@ image-ir:
@docker build \ @docker build \
--build-arg REPO=$(REPO) \ --build-arg REPO=$(REPO) \
--build-arg VERSION=$(VERSION) \ --build-arg VERSION=$(VERSION) \
--rm \
-f Dockerfile.ir \ -f Dockerfile.ir \
-t $(HUB_IMAGE)-ir:$(HUB_TAG) . -t $(HUB_IMAGE)-ir:$(HUB_TAG) .
# Build all Docker images # Build all Docker images
images: image-storage image-ir images: image-storage image-ir
# Run all code formaters
fmts: fmt imports
# Reformat code # Reformat code
fmt: fmt:
@[ ! -z `which goimports` ] || (echo "Install goimports" && exit 2) @echo "⇒ Processing gofmt check"
@for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \ @GO111MODULE=on gofmt -s -w cmd/ pkg/ misc/
echo "⇒ Processing $$f"; \
goimports -w $$f; \ # Reformat imports
done imports:
@echo "⇒ Processing goimports check"
@GO111MODULE=on goimports -w cmd/ pkg/ misc/
# Run Unit Test with go test
test:
@echo "⇒ Runnning go test"
@GO111MODULE=on go test ./...
# Run linters
lint:
@golangci-lint run
# Run linters in Docker
docker/lint:
docker run --rm -it \
-v `pwd`:/src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
golangci/golangci-lint:v1.30 bash -c 'cd /src/ && make lint'
# Print version # Print version
version: version:
@ -100,7 +130,7 @@ help:
@echo '' @echo ''
@echo ' Targets:' @echo ' Targets:'
@echo '' @echo ''
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort | uniq @awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
clean: clean:
rm -rf vendor rm -rf vendor