forked from cherts/pgscv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (92 loc) · 3.98 KB
/
Makefile
File metadata and controls
115 lines (92 loc) · 3.98 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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.10
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)
VERSION_BETA=1.0-$(BRANCH)-$(COMMIT)-$(DATE)-beta
LDFLAGS = -a -installsuffix cgo -ldflags "-X main.appName=${APPNAME} -X main.gitTag=${VERSION} -X main.gitCommit=${COMMIT} -X main.gitBranch=${BRANCH}"
MODERNIZE_CMD = go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.18.1
.PHONY: help \
clean lint test race \
build docker-lint docker-build docker-push go-update \
modernize modernize-fix modernize-check
.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%-25s\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-lint: ## Lint Dockerfile
@echo "Lint container Dockerfile"
docker run --rm -i -v $(PWD)/Dockerfile:/Dockerfile \
hadolint/hadolint hadolint --ignore DL3002 --ignore DL3008 --ignore DL3059 /Dockerfile
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-beta: ## Build docker image (beta)
docker build -t ${DOCKER_ACCOUNT}/${APPNAME}:v${VERSION_BETA} .
docker image prune --force --filter label=stage=intermediate
docker-push-beta: ## Push docker image (beta)
docker push ${DOCKER_ACCOUNT}/${APPNAME}:v${VERSION_BETA}
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}
modernize: modernize-fix ## Run gopls modernize check and fix
modernize-fix: ## Run gopls modernize fix
@echo "Running gopls modernize with -fix..."
go env -w GOFLAGS="-buildvcs=false"
$(MODERNIZE_CMD) -test -fix ./...
modernize-check: ## Run gopls modernize only check
@echo "Checking if code needs modernization..."
go env -w GOFLAGS="-buildvcs=false"
$(MODERNIZE_CMD) -test ./...