-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (74 loc) · 2.12 KB
/
Makefile
File metadata and controls
85 lines (74 loc) · 2.12 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
# Project related variables
PROJECTNAME=$(shell basename "$(PWD)")
M = $(shell printf "\033[34;1m▶\033[0m")
DONE="\n $(M) done ✨"
# Go related variables
GOBASE=$(shell pwd)
GOPATH=$(GOBASE)/vendor:$(GOBASE)
GOBIN=$(GOBASE)/bin
GO111MODULE=on
export GO111MODULE
.PHONY: help
help: Makefile
@echo "\n Choose a command run in "$(PROJECTNAME)":\n"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
## install: Install missing dependencies. Builds binary in ./bin
.PHONY: install
install:
@echo " $(M) Checking if there is any missing dependencies...\n"
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go get $(get) ./...
@echo $(DONE)
## build: Creates a docker image of the app
.PHONY: build
build:
@echo " $(M) Building the 🐳 image...\n"
docker build -t=$(PROJECTNAME) .
@echo $(DONE)
## fail: Forces a failed docker build of the app due to failing tests
.PHONY: fail
fail:
@echo " $(M) Failing the 🐳 image...\n"
docker build --build-arg FAILED=true -t=$(PROJECTNAME) .
@echo $(DONE)
## run: Runs the current docker image on port 8080
.PHONY: run
run:
@echo " $(M) Running the 🐳 image...\n"
docker run -it -p 8080:8080 --rm --name app -t $(PROJECTNAME)
@echo $(DONE)
## clean: Clean build files. Runs `go clean` internally
.PHONY: clean
clean:
@echo " $(M) 🧹 Cleaning build cache..."
go clean ./...
rm -rf bin
rm -rf cp.out
docker image rm $(PROJECTNAME)
@echo $(DONE)
## fmt: Runs gofmt on all source files
.PHONY: fmt
fmt:
@echo " $(M) 🏃 gofmt..."
@ret=0 && for d in $$(go list -f '{{.Dir}}' ./...); do \
gofmt -l -w $$d/*.go || ret=$$? ; \
done ; exit $$ret
@echo $(DONE)
## test: Runs all the tests.
.PHONY: test
test:
@echo " $(M) 🏃 all the tests...\n"
cd "$$GOBASE"
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go test ./...
@echo $(DONE)
## coverage: Tests code coverage
.PHONY: coverage
coverage:
@echo " $(M) 👀 testing code coverage...\n"
cd "$$GOBASE"
@GOPATH=$(GOPATH) GOBIN=$(GOBIN) go test ./... -coverprofile cp.out
@echo $(DONE)
## missing: Displays lines of code missing from coverage
.PHONY: missing
missing:
@echo " $(M) 👀 missing coverage...\n"
grep -v -e $" 1$" ./cp.out