-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (110 loc) · 3.58 KB
/
Makefile
File metadata and controls
142 lines (110 loc) · 3.58 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
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
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 := $(if $(prefix),$(prefix),/usr/local)
BIN_DIR := $(DESTDIR)$(PREFIX)/bin/
MAN_DIR := $(DESTDIR)$(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)
$(GO) run github.com/golangci/golangci-lint/cmd/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:
@echo "golangci-lint is now managed via go.mod and tools.go"
@echo "No installation needed - it will be automatically downloaded when running 'make check'"
.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)