forked from lesovsky/pgscv
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
87 lines (71 loc) · 2.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
DOCKER_ACCOUNT = cherts
APPNAME = pgscv
APPOS = linux
#APPOS = ${GOOS}
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
ifeq ($(TAG),)
VERSION := 0.9
else
#VERSION := $(TAG:v%=%)
VERSION := $(TAG)
endif
ifneq ($(COMMIT), $(TAG_COMMIT))
VERSION := $(VERSION)-next-$(DATE)
endif
ifeq ($(VERSION),)
VERSION := $(COMMIT)-$(DATA)
endif
ifneq ($(shell git status --porcelain),)
VERSION := $(VERSION)-dirty
endif
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
LDFLAGS = -a -installsuffix cgo -ldflags "-X main.appName=${APPNAME} -X main.gitTag=${VERSION} -X main.gitCommit=${COMMIT} -X main.gitBranch=${BRANCH}"
.PHONY: help \
clean lint test race \
build docker-build docker-push go-update
.DEFAULT_GOAL := help
help: ## Display this help screen
@echo "Makefile available targets:"
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " * \033[36m%-15s\033[0m %s\n", $$1, $$2}'
clean: ## Clean
rm -f ./bin/${APPNAME} ./bin/${APPNAME}.tar.gz ./bin/${APPNAME}.version ./bin/${APPNAME}.sha256
rm -rf ./bin
go-update: # Update go mod
go mod tidy -compat=1.23
go get -u ./cmd
go mod download
go get -u ./cmd
go mod download
dep: ## Get the dependencies
go mod download
lint: ## Lint the source files
go env -w GOFLAGS="-buildvcs=false"
REVIVE_FORCE_COLOR=1 revive -formatter friendly ./...
gosec -quiet ./...
test: dep lint ## Run tests
go test -race -timeout 300s -coverprofile=.test_coverage.txt ./... && \
go tool cover -func=.test_coverage.txt | tail -n1 | awk '{print "Total test coverage: " $$3}'
@rm .test_coverage.txt
race: dep ## Run data race detector
go test -race -short -timeout 300s -p 1 ./...
build: dep ## Build
mkdir -p ./bin
CGO_ENABLED=0 GOOS=${APPOS} GOARCH=${GOARCH} go build ${LDFLAGS} -o bin/${APPNAME} ./cmd
docker-build: ## Build docker image
docker build -t ${DOCKER_ACCOUNT}/${APPNAME}:${TAG} .
docker image prune --force --filter label=stage=intermediate
docker tag ${DOCKER_ACCOUNT}/${APPNAME}:${TAG} ${DOCKER_ACCOUNT}/${APPNAME}:latest
docker-push: ## Push docker image
docker push ${DOCKER_ACCOUNT}/${APPNAME}:${TAG}
docker push ${DOCKER_ACCOUNT}/${APPNAME}:latest
docker-build-test-runner: ## Build docker image with testing environment for CI
$(eval VERSION := $(shell grep -E 'LABEL version' testing/docker-test-runner/Dockerfile |cut -d = -f2 |tr -d \"))
cd ./testing/docker-test-runner; \
docker build -t ${DOCKER_ACCOUNT}/pgscv-test-runner:${VERSION} .
docker-push-test-runner: ## Push testing docker image to registry
$(eval VERSION := $(shell grep -E 'LABEL version' testing/docker-test-runner/Dockerfile |cut -d = -f2 |tr -d \"))
cd ./testing/docker-test-runner; \
docker push ${DOCKER_ACCOUNT}/pgscv-test-runner:${VERSION}