[#1578] Minor Makefile fixes

- Add VERSION file to make it work without .git folder
- Remove obsolete GO111MODULE flag
- Move linter version to variable
- clean .cache on `make clean`
- Move help target to a separate help.mk file

Signed-off-by: Stanislav Bogatyrev <stanislav@nspcc.ru>
This commit is contained in:
Stanislav Bogatyrev 2022-07-05 16:56:30 +03:00 committed by fyrchik
parent a153e040cb
commit 930b51b57d
4 changed files with 27 additions and 18 deletions

View file

@ -2,7 +2,7 @@
SHELL = bash SHELL = bash
REPO ?= $(shell go list -m) REPO ?= $(shell go list -m)
VERSION ?= $(shell git describe --tags --dirty --always) VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
BUILD ?= $(shell date -u --iso=seconds) BUILD ?= $(shell date -u --iso=seconds)
DEBUG ?= false DEBUG ?= false
@ -10,6 +10,7 @@ HUB_IMAGE ?= nspccdev/neofs
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')" HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
GO_VERSION ?= 1.17 GO_VERSION ?= 1.17
LINT_VERSION ?= 1.46.2
ARCH = amd64 ARCH = amd64
BIN = bin BIN = bin
@ -27,10 +28,12 @@ BINS = $(addprefix $(BIN)/, $(CMDS))
# Just `make` will build all possible binaries # Just `make` will build all possible binaries
all: $(DIRS) $(BINS) all: $(DIRS) $(BINS)
# help target
include help.mk
$(BINS): $(DIRS) dep $(BINS): $(DIRS) dep
@echo "⇒ Build $@" @echo "⇒ Build $@"
CGO_ENABLED=0 \ CGO_ENABLED=0 \
GO111MODULE=on \
go build -v -trimpath \ go build -v -trimpath \
-ldflags "-X $(REPO)/misc.Version=$(VERSION) \ -ldflags "-X $(REPO)/misc.Version=$(VERSION) \
-X $(REPO)/misc.Build=$(BUILD) \ -X $(REPO)/misc.Build=$(BUILD) \
@ -54,11 +57,9 @@ prepare-release: docker/all
dep: dep:
@printf "⇒ Download requirements: " @printf "⇒ Download requirements: "
CGO_ENABLED=0 \ CGO_ENABLED=0 \
GO111MODULE=on \
go mod download && echo OK go mod download && echo OK
@printf "⇒ Tidy requirements : " @printf "⇒ Tidy requirements : "
CGO_ENABLED=0 \ CGO_ENABLED=0 \
GO111MODULE=on \
go mod tidy -v && echo OK go mod tidy -v && echo OK
# Regenerate proto files: # Regenerate proto files:
@ -112,17 +113,17 @@ fmts: fmt imports
# Reformat code # Reformat code
fmt: fmt:
@echo "⇒ Processing gofmt check" @echo "⇒ Processing gofmt check"
@GO111MODULE=on gofmt -s -w cmd/ pkg/ misc/ @gofmt -s -w cmd/ pkg/ misc/
# Reformat imports # Reformat imports
imports: imports:
@echo "⇒ Processing goimports check" @echo "⇒ Processing goimports check"
@GO111MODULE=on goimports -w cmd/ pkg/ misc/ @goimports -w cmd/ pkg/ misc/
# Run Unit Test with go test # Run Unit Test with go test
test: test:
@echo "⇒ Running go test" @echo "⇒ Running go test"
@GO111MODULE=on go test ./... @go test ./...
# Run linters # Run linters
lint: lint:
@ -134,23 +135,14 @@ docker/lint:
-v `pwd`:/src \ -v `pwd`:/src \
-u `stat -c "%u:%g" .` \ -u `stat -c "%u:%g" .` \
--env HOME=/src \ --env HOME=/src \
golangci/golangci-lint:v1.42.1 bash -c 'cd /src/ && make lint' golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
# Print version # Print version
version: version:
@echo $(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
clean: clean:
rm -rf vendor rm -rf vendor
rm -rf .cache
rm -rf $(BIN) rm -rf $(BIN)
rm -rf $(RELEASE) rm -rf $(RELEASE)

1
VERSION Normal file
View file

@ -0,0 +1 @@
v0.28.3

View file

@ -28,6 +28,11 @@ Use `vX.Y.Z` tag for releases and `vX.Y.Z-rc.N` for release candidates
following the [semantic versioning](https://semver.org/) standard. Tag must be following the [semantic versioning](https://semver.org/) standard. Tag must be
created from the latest commit of the master branch. created from the latest commit of the master branch.
## Update VERSION files
Make sure the VERSION file contains correct release version. It must be the tag
you have just created.
## Push changes and release tag to GitHub ## Push changes and release tag to GitHub
This step should bypass the default PR mechanism to get a correct result (so This step should bypass the default PR mechanism to get a correct result (so

11
help.mk Normal file
View file

@ -0,0 +1,11 @@
.PHONY: help
# 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 | uniq