-
Notifications
You must be signed in to change notification settings - Fork 48
/
Makefile
145 lines (113 loc) · 3.52 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
export GOPROXY=https://proxy.golang.org
SHELL= /bin/bash
GO ?= go
GOPATH := $(shell $(GO) env GOPATH)
GOBIN := $(shell $(GO) env GOBIN)
BUILD_DIR := ./build
PREFIX := /usr/local
BIN_DIR := $(PREFIX)/bin/
MAN_DIR := ${PREFIX}/share/man
NAME := vgrep
PROJECT := github.com/vrothberg/vgrep
VERSION := $(shell cat ./VERSION)
COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker)
PATH := $(CURDIR)/test/bin:$(PATH)
GO_SRC=$(shell find . -name \*.go)
GO_BUILD=$(GO) build $(GO_BUILD_EXTRA_FLAGS)
# Go module support: set `-mod=vendor` to use the vendored sources
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
endif
COVERAGE_PATH ?= $(shell pwd)/.coverage
COVERAGE_PROFILE ?= $(shell pwd)/coverage.txt
export COVERAGE_PATH
export COVERAGE_PROFILE
$(shell mkdir -p ${COVERAGE_PATH})
ifeq ($(GOBIN),)
GOBIN := $(GOPATH)/bin
endif
GOMD2MAN ?= $(shell command -v go-md2man || echo '$(GOBIN)/go-md2man')
MANPAGES_MD = $(wildcard docs/*.md)
MANPAGES ?= $(MANPAGES_MD:%.md=%)
all: check build
.PHONY: build
build: $(GO_SRC)
$(GO_BUILD) -o $(BUILD_DIR)/$(NAME) -ldflags "-s -w -X main.version=${VERSION}-$(COMMIT)"
.PHONY: build.coverage
build.coverage: $(GO_SRC)
$(GO) test \
-covermode=count \
-coverpkg=./... \
-mod=vendor \
-tags coverage \
-buildmode=pie -c -o $(BUILD_DIR)/$(NAME) \
-ldflags "-s -w -X main.version=${VERSION}-$(COMMIT)"
.PHONY: codecov
codecov:
bash <(curl -s https://codecov.io/bash) -v -s $(COVERAGE_PATH) -f "coverprofile.integration.*"
.PHONY: release
release: $(GO_SRC)
$(GO_BUILD) -buildmode=pie -o $(BUILD_DIR)/$(NAME) -ldflags "-s -w -X main.version=${VERSION}"
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) docs/*.1
.PHONY: deps
deps:
$(GO) get -u ./...
.PHONY: check
check: $(GO_SRC)
${BUILD_DIR}/golangci-lint run
.PHONY: test
test: test-integration
.PHONY: test-integration
test-integration:
bats test/*.bats
.PHONY: test-integration.coverage
test-integration.coverage:
export COVERAGE=1; bats test/*.bats
.PHONY: vendor
vendor:
GO111MODULE=on go mod tidy
GO111MODULE=on go mod vendor
GO111MODULE=on go mod verify
.install.tools:
export \
VERSION=v1.60.3 \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=${BUILD_DIR} && \
curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
.install.go-md2man:
ifeq ($(GOMD2MAN),)
$(GO) install github.com/cpuguy83/go-md2man
endif
.PHONY: install
install: install-docs
install -d -m 755 $(BIN_DIR)
install -m 755 $(BUILD_DIR)/$(NAME) $(BIN_DIR)
.PHONY: install-docs
install-docs: docs
install -d -m 755 ${MAN_DIR}/man1
install -m 644 docs/*.1 ${MAN_DIR}/man1/
.PHONY: uninstall
uninstall:
rm $(BIN_DIR)/$(NAME)
# CONTAINER MAKE TARGETS
CONTAINER_IMAGE := vgrepdev
CONTAINER_RUNCMD := run --rm --privileged -v `pwd`:/go/src/$(PROJECT)
.PHONY: container-image
container-image:
$(CONTAINER_RUNTIME) build -f Dockerfile -t $(CONTAINER_IMAGE) --build-arg PROJECT=$(PROJECT) .
.PHONY: container-build
container-build: container-image
$(CONTAINER_RUNTIME) $(CONTAINER_RUNCMD) $(CONTAINER_IMAGE) make build
.PHONY: container-release
container-release: container-image
$(CONTAINER_RUNTIME) $(CONTAINER_RUNCMD) $(CONTAINER_IMAGE) make release
.PHONY: container-shell
container-shell: container-image
$(CONTAINER_RUNTIME) $(CONTAINER_RUNCMD) -it $(CONTAINER_IMAGE) sh
$(MANPAGES): %:%.md
sed -e 's/\((vgrep.*\.md)\)//' -e 's/\[\(vgrep.*\)\]/\1/' $< | $(GOMD2MAN) -in /dev/stdin -out $@
.PHONY: docs
docs: $(MANPAGES)