forked from xmidt-org/themis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (73 loc) · 2.67 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
88
89
90
91
DEFAULT: build
GO ?= go
GOFMT ?= $(GO)fmt
APP := themis
DOCKER_ORG := xmidt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
BINARY := $(FIRST_GOPATH)/bin/$(APP)
VERSION ?= $(shell git describe --tag --always --dirty)
PROGVER = $(shell git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/')
BUILDTIME = $(shell date -u '+%Y-%m-%d %H:%M:%S')
GITCOMMIT = $(shell git rev-parse --short HEAD)
GOBUILDFLAGS = -a -ldflags "-w -s -X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(VERSION)" -o $(APP)
.PHONY: vendor
vendor:
$(GO) mod vendor
.PHONY: build
build: vendor
CGO_ENABLED=0 $(GO) build $(GOBUILDFLAGS)
.PHONY: version
version:
@echo $(PROGVER)
# If the first argument is "update-version"...
ifeq (update-version,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "update-version"
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(RUN_ARGS):;@:)
endif
.PHONY: update-version
update-version:
@echo "Update Version $(PROGVER) to $(RUN_ARGS)"
git tag v$(RUN_ARGS)
.PHONY: install
install: vendor
$(GO) install -ldflags "-w -s -X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
.PHONY: release-artifacts
release-artifacts: vendor
mkdir -p ./.ignore
GOOS=darwin GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).darwin-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
GOOS=linux GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).linux-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
.PHONY: docker
docker:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GITCOMMIT=$(GITCOMMIT) \
--build-arg BUILDTIME='$(BUILDTIME)' \
-f ./deploy/Dockerfile -t $(DOCKER_ORG)/$(APP):$(PROGVER) .
.PHONY: local-docker
local-docker:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GITCOMMIT=$(GITCOMMIT) \
--build-arg BUILDTIME='$(BUILDTIME)' \
-f ./deploy/Dockerfile -t $(DOCKER_ORG)/$(APP):local .
.PHONY: style
style:
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
.PHONY: test
test: vendor
GO111MODULE=on $(GO) test -v -race -coverprofile=coverage.txt ./...
GO111MODULE=on $(GO) test -v -race -json ./... > report.json
.PHONY: test-cover
test-cover: test
$(GO) tool cover -html=coverage.txt
.PHONY: codecov
codecov: test
curl -s https://codecov.io/bash | bash
.PHONEY: it
it:
./it.sh
.PHONY: clean
clean:
rm -rf ./$(APP) ./.ignore ./coverage.txt ./vendor report.json