-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (43 loc) · 1.42 KB
/
Makefile
File metadata and controls
60 lines (43 loc) · 1.42 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
SHELL := /bin/bash
export GO111MODULE=on
export PATH := $(GOPATH)/bin:$(PATH)
BINARY_VERSION?=0.0.1
BINARY_OUTPUT?=githubby
COMMIT?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X main.Version=$(BINARY_VERSION) -X main.Commit=$(COMMIT) -X main.BuildDate=$(BUILD_DATE)"
define timed_function
@d=$$(date +%s); \
$(shell echo $1); \
echo "=> Ran $1 in $$(($$(date +%s)-d)) seconds"
endef
.PHONY: all install uninstall build test clean deps upgrade tidy lint vet
all: deps build
install:
$(call timed_function,'go install -v $(LDFLAGS)')
uninstall:
$(call timed_function,'rm -f $(GOPATH)/bin/$(BINARY_OUTPUT)')
build:
$(call timed_function,'go build -v $(LDFLAGS) -o $(BINARY_OUTPUT)')
test:
$(call timed_function,'go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...')
clean:
$(call timed_function,'go clean')
$(call timed_function,'rm -f $(BINARY_OUTPUT)')
$(call timed_function,'rm -f coverage.txt')
deps:
$(call timed_function,'go mod download')
$(call timed_function,'go build -v ./...')
upgrade:
$(call timed_function,'go get -u ./...')
$(call timed_function,'go mod tidy')
tidy:
$(call timed_function,'go mod tidy')
vet:
$(call timed_function,'go vet ./...')
lint: vet
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed, skipping"; \
fi