-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (108 loc) · 3.52 KB
/
Makefile
File metadata and controls
141 lines (108 loc) · 3.52 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
export GOPROXY=https://proxy.golang.org
SHELL= /bin/bash
.DELETE_ON_ERROR:
.DEFAULT_GOAL := all
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 -mod=vendor
COVERAGE_PATH ?= $(shell pwd)/.coverage
COVERAGE_PROFILE ?= $(shell pwd)/coverage.txt
export COVERAGE_PATH
export COVERAGE_PROFILE
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)
@mkdir -p $(COVERAGE_PATH)
$(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:
go mod tidy
go mod vendor
go mod verify
.PHONY: .install.tools .install.go-md2man
.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:
@echo "go-md2man is now managed via go.mod and tools.go"
@echo "No installation needed - it will be automatically downloaded when generating docs"
.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/' $< | $(GO) run github.com/cpuguy83/go-md2man -in /dev/stdin -out $@
.PHONY: docs
docs: $(MANPAGES)