-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
153 lines (118 loc) · 4.42 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
PROJECTNAME ?= $(shell basename "$(PWD)")
BASE = $(shell pwd)
BUILD_DIR ?= $(BASE)/build
VETARGS ?= -all
GOFMT_FILES ?= $$(find . -name '*.go' | grep -v vendor)
# Ensure GOPATH is set
GOPATH ?= $(shell go env GOPATH)
TMP_GOPATH ?= /tmp/gonotify-go
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
GO111MODULE ?= on
export GO111MODULE
GOPROXY ?= https://proxy.golang.org
export GOPROXY
# Tools
GOBINDATA ?= $(GOBIN)/go-bindata
# React
REACT_APP_PATH = pkg/ui/react-app
REACT_APP_SOURCE_FILES = $(wildcard $(REACT_APP_PATH)/public/* $(REACT_APP_PATH)/src/* $(REACT_APP_PATH)/package.json)
REACT_APP_OUTPUT_DIR = $(REACT_APP_PATH)/build
REACT_APP_NODE_MODULES_PATH = $(REACT_APP_PATH)/node_modules
.PHONY: help
help: ## Display usage and help message.
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-z0-9A-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
$(GOBINDATA):
@echo ">> installing go-bindata"
@GO111MODULE='off' go get -u github.com/go-bindata/go-bindata/...
$(REACT_APP_NODE_MODULES_PATH): $(REACT_APP_PATH)/package.json $(REACT_APP_PATH)/yarn.lock
@echo ">> installing npm dependencies for React UI"
@cd $(REACT_APP_PATH) && yarn --frozen-lockfile
$(REACT_APP_OUTPUT_DIR): $(REACT_APP_NODE_MODULES_PATH) $(REACT_APP_SOURCE_FILES)
@echo ">> building React app"
@cd $(REACT_APP_PATH) && yarn build
.PHONY: run
run: ## Runs the program.
run:
@echo ">> starting $(PROJECTNAME)"
@go run cmd/gonotify/main.go
.PHONY: run-prod
run-prod: ## runs the program in release mode.
run-prod:
@echo ">> starting $(PROJECTNAME) in release mode"
@GIN_MODE=release go run cmd/gonotify/main.go
.PHONY: build
build: ## Builds the GoNotify binary.
build: assets
@echo ">> building $(PROJECTNAME) binary"
@go build -o $(BUILD_DIR)/gonotify ./cmd/gonotify
.PHONY: build-static
build-static: ## Builds a statically linked binary for easy deployment
build-static: assets
@echo ">> building statically linked $(PROJECTNAME) binary"
@GOOS=linux go build -ldflags "-linkmode external -extldflags -static" -o $(BUILD_DIR)/gonotify-static ./cmd/gonotify
.PHONY: build-cli
build-cli: ## Builds gncli - the GoNotify CLI client.
build-cli:
@echo ">> building gncli binary"
@go build -o $(BUILD_DIR)/gncli ./cmd/gncli
.PHONY: assets
assets: ## Repacks all static assets into go file for easier deploy.
assets: $(GOBINDATA) $(REACT_APP_OUTPUT_DIR)
@echo ">> deleting asset file"
@rm pkg/ui/bindata.go || true
@echo ">> writing assets"
@go-bindata -pkg ui -o pkg/ui/bindata.go -prefix "pkg/ui/react-app/build" pkg/ui/react-app/build/...
@go fmt ./pkg/ui
.PHONY: vet
vet: ## Runs go vet against all packages.
vet:
@echo ">> running go vet on packages"
@go vet $(VETARGS) ./pkg/... ./cmd/... ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
.PHONY: fmt
fmt: ## Format all go files using go fmt.
fmt:
@echo ">> running go fmt on all go files"
@gofmt -w $(GOFMT_FILES)
.PHONY: react-app-start
react-app-start: ## Start React app for local development
react-app-start: $(REACT_APP_NODE_MODULES_PATH)
@echo ">> running React app"
@cd $(REACT_APP_PATH) && yarn start
.PHONY: react-app-lint
react-app-lint: $(REACT_APP_NODE_MODULES_PATH)
@echo ">> running React app linting"
cd $(REACT_APP_PATH) && yarn lint:ci
.PHONY: react-app-lint-fix
react-app-lint-fix:
@echo ">> running React app linting and fixing errors where possible"
cd $(REACT_APP_PATH) && yarn lint
.PHONY: react-app-test
react-app-test: | $(REACT_APP_NODE_MODULES_PATH) react-app-lint
@echo ">> running React app tests"
cd $(REACT_APP_PATH) && export CI=true && yarn test --no-watch --coverage
.PHONY: test
test: ## Run all unit tests
test:
@echo ">> running unit tests"
@go test ./...
.PHONY: coverage
coverage: ## Generate and open a HTML test coverage report
coverage:
@echo ">> generating coverage report for all tests"
@go test -cover -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@xdg-open coverage.html
.PHONY: clean
clean: ## Deletes temporary files created by this Makefile's targets
clean:
@echo ">> deleting files made by target 'coverage'"
@rm coverage.out || true
@rm coverage.html || true
@echo ">> deleting binaries"
@rm build/* || true