-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
125 lines (101 loc) · 3.4 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
# Setup name variables for the package/tool
NAME := func
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
# App version
VERSION := $(shell cat VERSION.txt)
# Binary tool dependencies and build artifacts
BINDIR := $(PREFIX)/bin
export GOBIN :=$(BINDIR)
export PATH := $(GOBIN):$(PATH)
LINTER := $(BINDIR)/golint
STATIC_CHECK := $(BINDIR)/staticcheck
PACKR2 := $(BINDIR)/packr2
SEMBUMP := $(BINDIR)/sembump
BUILDDIR := $(PREFIX)/build
all: help
.PHONY: ci ## Runs all tests and static code analysis
ci: build fmt lint test staticcheck vet
$(PACKR2):
go install github.com/gobuffalo/packr/v2/packr2
.PHONY: build
build: $(PACKR2) ## Builds a static executable
@echo "+ $@"
@packr2
@CGO_ENABLED=0 go build -o $(BUILDDIR)/$(NAME) .
@packr2 clean
.PHONY: install
install: $(PACKR2)
@echo "+ $@"
@GO111MODULE=on packr2 install
@packr2 clean
.PHONY: init-releaser
init-releaser: $(PACKR2) ## Initializes goreleaser for GitHub actions
@echo "+ $@"
@go mod tidy
@packr2
.PHONY: fmt
fmt: ## Verifies all files have men `gofmt`ed
@echo "+ $@"
@gofmt -s -l . | grep -v vendor | tee /dev/stderr
$(LINTER):
go install golang.org/x/lint/golint
.PHONY: lint
lint: $(LINTER) ## Verifies `golint` passes
@echo "+ $@"
@golint ./... | grep -v vendor | tee /dev/stderr
.PHONY: vet
vet: ## Verifies `go vet` passes
@echo "+ $@"
@go vet $(shell go list ./... | grep -v vendor) | tee /dev/stderr
$(STATIC_CHECK):
go install honnef.co/go/tools/cmd/staticcheck
.PHONY: staticcheck
staticcheck: $(STATIC_CHECK) ## Verifies `staticcheck` passes
@echo "+ $@"
@staticcheck $(shell go list ./... | grep -v vendor) | tee /dev/stderr
.PHONY: test
test: ## Runs all go tests
@echo "+ $@"
@go test -v -race $(shell go list ./... | grep -v vendor)
.PHONY: cover
cover: ## Runs all go tests (including integration tests) with coverage
@echo "" > coverage.txt
@for d in $(shell go list ./... | grep -v vendor); do \
go test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
if [ -f profile.out ]; then \
cat profile.out >> coverage.txt; \
rm profile.out; \
fi; \
done;
$(SHOULDERS):
go get -u github.com/gobuffalo/shoulders
.PHONY: shoulders
shoulders: $(SHOULDERS) ## Generates SHOULDERS.md
@echo "+ $@"
@shoulders -w -n $(NAME)
$(SEMBUMP):
GO111MODULE=off go get -u github.com/jessfraz/junk/sembump
.PHONY: bump-version
BUMP := patch
bump-version: $(SEMBUMP) ## Bump the version in the version file. Set BUMP to [ patch | major | minor ].
$(eval NEW_VERSION = $(shell $(BINDIR)/sembump --kind $(BUMP) $(VERSION)))
@echo "Bumping VERSION.txt from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION.txt
@echo "Updating links in README.md"
sed -i '' s/$(subst v,,$(VERSION))/$(subst v,,$(NEW_VERSION))/g README.md
git add VERSION.txt README.md
git commit -vsam "Bump version to $(NEW_VERSION)"
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"
.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -a $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a build."
.PHONY: clean
clean: $(PACKR2) ## Cleanup any build binaries or packages
@echo "+ $@"
@$(RM) -r $(BUILDDIR)
@packr2 clean
.PHONY: help
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'