-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
60 lines (48 loc) · 1.55 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
version ?= latest
img = go-tfidf:$(version)
imgdev = go-tfidfdev:$(version)
uid=$(shell id -u $$USER)
gid=$(shell id -g $$USER)
dockerbuilduser=--build-arg USER_ID=$(uid) --build-arg GROUP_ID=$(gid) --build-arg USER
wd=$(shell pwd)
modcachedir=$(wd)/.gomodcachedir
cachevol=$(modcachedir):/go/pkg/mod
appvol=$(wd):/app
run=docker run --rm -ti -v $(appvol) -v $(cachevol) $(imgdev)
runbuild=docker run --rm -ti -e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 -v $(appvol) -v $(cachevol) $(imgdev)
cov=coverage.out
covhtml=coverage.html
all: check build
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Variable '$*' not set"; \
exit 1; \
fi
# WHY: If cache dir does not exist it is mapped inside container as root
# If it exists it is mapped belonging to the non-root user inside the container
modcache:
@mkdir -p $(modcachedir)
imagedev:
docker build . -t $(imgdev) -f ./hack/Dockerfile $(dockerbuilduser)
release: guard-version
git tag -a $(version) -m "Generated release "$(version)
git push origin $(version)
check: modcache imagedev
$(run) go test -timeout 60s -race -coverprofile=$(cov) ./...
coverage: modcache check
$(run) go tool cover -html=$(cov) -o=$(covhtml)
xdg-open coverage.html
static-analysis: modcache imagedev
$(run) golangci-lint run ./...
modtidy: modcache imagedev
$(run) go mod tidy
fmt: modcache imagedev
$(run) gofmt -w -s -l .
githooks:
@echo "copying git hooks"
@mkdir -p .git/hooks
@cp hack/githooks/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "git hooks copied"
shell: modcache imagedev
$(run) sh