forked from abice/go-enum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (73 loc) · 1.95 KB
/
Makefile
File metadata and controls
96 lines (73 loc) · 1.95 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
.DEFAULT_GOAL:=all
ifdef VERBOSE
V = -v
else
.SILENT:
endif
GO ?= GO111MODULE=on go
COVERAGEDIR= coverage
SERVICE=local
ifdef GITHUB_ACTIONS
SERVICE=github-actions
endif
DATE := $(shell date -u '+%FT%T%z')
GITHUB_SHA ?= $(shell git rev-parse HEAD)
GITHUB_REF ?= local
LDFLAGS += -X "main.version=$(GITHUB_REF)"
LDFLAGS += -X "main.commit=$(GITHUB_SHA)"
LDFLAGS += -X "main.date=$(DATE)"
LDFLAGS += -X "main.builtBy=$(USER)"
LDFLAGS += -extldflags '-static'
define goinstall
mkdir -p $(shell pwd)/bin
echo "Installing $(1)"
GOBIN=$(shell pwd)/bin go install $(1)
endef
GOBINDATA=bin/go-bindata
GOIMPORTS=bin/goimports
GOVERALLS=bin/goveralls
MOCKGEN=bin/mockgen
deps: $(MOCKGEN)
deps: $(GOBINDATA)
deps: $(GOIMPORTS)
PACKAGES='./generator' './example'
.PHONY: all
all: build fmt test example cover install
build: deps
$(GO) generate ./generator
if [ ! -d bin ]; then mkdir bin; fi
$(GO) build -v -o bin/go-enum -ldflags='-X "main.version=example" -X "main.commit=example" -X "main.date=example" -X "main.builtBy=example"' .
fmt:
gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*")
test: gen-test generate
$(GO) test -v -race -coverprofile=coverage.out ./...
cover: gen-test test
$(GO) tool cover -html=coverage.out -o coverage.html
tc: test cover
coveralls: $(GOVERALLS)
$(GOVERALLS) -coverprofile=coverage.out -service=$(SERVICE) -repotoken=$(COVERALLS_TOKEN)
clean:
$(GO) clean
rm -f bin/go-enum
rm -rf coverage/
rm -rf bin/
rm -rf dist/
.PHONY: generate
generate:
$(GO) generate $(PACKAGES)
gen-test: build
$(GO) generate $(PACKAGES)
install:
$(GO) install
phony: clean tc build
.PHONY: example
example:
$(GO) generate ./example/...
bin/goimports: go.sum
$(call goinstall,golang.org/x/tools/cmd/goimports)
bin/mockgen: go.sum
$(call goinstall,github.com/golang/mock/mockgen)
bin/goveralls: go.sum
$(call goinstall,github.com/mattn/goveralls)
bin/go-bindata: go.sum
$(call goinstall,github.com/kevinburke/go-bindata/go-bindata)