2020-09-18 08:25:11 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL = bash
|
|
|
|
|
2022-09-06 07:50:50 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --match "v*" --abbrev=8 --dirty --always)
|
2020-09-21 18:17:49 +00:00
|
|
|
|
|
|
|
.PHONY: dep fmts fmt imports protoc test lint version help
|
2020-09-18 08:25:11 +00:00
|
|
|
|
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Tidy requirements : "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go mod tidy -v && echo OK
|
|
|
|
@printf "⇒ Download requirements: "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go mod download && echo OK
|
|
|
|
@printf "⇒ Install test requirements: "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
2021-12-02 13:15:44 +00:00
|
|
|
go test ./... && echo OK
|
2020-09-18 08:25:11 +00:00
|
|
|
|
2020-12-30 09:32:29 +00:00
|
|
|
# Run all code formatters
|
2020-09-18 08:25:11 +00:00
|
|
|
fmts: fmt imports
|
2020-01-30 12:47:05 +00:00
|
|
|
|
2019-11-20 13:40:06 +00:00
|
|
|
# Reformat code
|
2020-09-18 08:25:11 +00:00
|
|
|
fmt:
|
|
|
|
@echo "⇒ Processing gofmt check"
|
2019-11-20 13:40:06 +00:00
|
|
|
@for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \
|
2020-09-18 08:25:11 +00:00
|
|
|
GO111MODULE=on gofmt -s -w $$f; \
|
2019-11-20 13:40:06 +00:00
|
|
|
done
|
|
|
|
|
2020-09-18 08:25:11 +00:00
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \
|
|
|
|
GO111MODULE=on goimports -w $$f; \
|
2019-11-20 13:40:06 +00:00
|
|
|
done
|
|
|
|
|
2020-09-21 18:17:49 +00:00
|
|
|
# Regenerate code for proto files
|
2020-08-12 09:49:11 +00:00
|
|
|
protoc:
|
2022-12-09 10:41:35 +00:00
|
|
|
@GOPRIVATE=github.com/TrueCloudLab go mod vendor
|
2020-09-18 08:25:11 +00:00
|
|
|
# Install specific version for protobuf lib
|
2021-11-12 07:57:42 +00:00
|
|
|
@go list -f '{{.Path}}/...@{{.Version}}' -m google.golang.org/protobuf | xargs go install -v
|
2020-09-18 08:25:11 +00:00
|
|
|
# Protoc generate
|
2019-11-20 13:40:06 +00:00
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
|
2020-09-18 08:25:11 +00:00
|
|
|
echo "⇒ Processing $$f "; \
|
2019-11-20 13:40:06 +00:00
|
|
|
protoc \
|
2021-09-28 15:10:48 +00:00
|
|
|
--proto_path=.:./vendor:/usr/local/include \
|
|
|
|
--go_out=. --go_opt=paths=source_relative \
|
|
|
|
--go-grpc_opt=require_unimplemented_servers=false \
|
|
|
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
2019-11-20 13:40:06 +00:00
|
|
|
done
|
2020-09-18 08:25:11 +00:00
|
|
|
rm -rf vendor
|
2020-09-21 18:17:49 +00:00
|
|
|
|
|
|
|
# Run Unit Test with go test
|
|
|
|
test:
|
2020-12-30 09:32:29 +00:00
|
|
|
@echo "⇒ Running go test"
|
2020-09-21 18:17:49 +00:00
|
|
|
@GO111MODULE=on go test ./...
|
|
|
|
|
|
|
|
# Run linters
|
|
|
|
lint:
|
|
|
|
@golangci-lint run
|
|
|
|
|
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@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 -u
|