-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
120 lines (85 loc) · 3.75 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
# Run `make help` to display help
.DEFAULT_GOAL := help
# --- Global -------------------------------------------------------------------
O = out
COVERAGE = 66
VERSION ?= $(shell git describe --tags --dirty --always)
all: build test check-coverage lint ## build, test, check coverage and lint
@if [ -e .git/rebase-merge ]; then git --no-pager log -1 --pretty='%h %s'; fi
@echo '$(COLOUR_GREEN)Success$(COLOUR_NORMAL)'
ci: clean check-uptodate all ## Full clean build and up-to-date checks as run on CI
check-uptodate: tidy
test -z "$$(git status --porcelain -- go.mod go.sum)" || { git status; false; }
clean:: ## Remove generated files
-rm -rf $(O)
.PHONY: all check-uptodate ci clean
# --- Build --------------------------------------------------------------------
GO_LDFLAGS = -X main.version=$(VERSION)
CMDS = .
build: | $(O) ## Build reflect binaries
go build -o $(O) -ldflags='$(GO_LDFLAGS)' $(CMDS)
install: ## Build and install binaries in $GOBIN
go install -ldflags='$(GO_LDFLAGS)' $(CMDS)
tidy: ## Tidy go modules with "go mod tidy"
go mod tidy
.PHONY: build install tidy
# --- Test ---------------------------------------------------------------------
COVERFILE = $(O)/coverage.txt
test: | $(O) ## Run tests and generate a coverage file
go test -coverprofile=$(COVERFILE) ./...
check-coverage: test ## Check that test coverage meets the required level
@go tool cover -func=$(COVERFILE) | $(CHECK_COVERAGE) || $(FAIL_COVERAGE)
cover: test ## Show test coverage in your browser
go tool cover -html=$(COVERFILE)
CHECK_COVERAGE = awk -F '[ \t%]+' '/^total:/ {print; if ($$3 < $(COVERAGE)) exit 1}'
FAIL_COVERAGE = { echo '$(COLOUR_RED)FAIL - Coverage below $(COVERAGE)%$(COLOUR_NORMAL)'; exit 1; }
.PHONY: check-coverage cover test
# --- Lint ---------------------------------------------------------------------
lint: ## Lint go source code
golangci-lint run
.PHONY: lint
# --- frontend -----------------------------------------------------------------
frontend: | $(O) ## Build frontend, typically iterate with npm and inside frontend
rm -rf $(O)/public
cp -r frontend $(O)/public
firebase-deploy: frontend ## Deploy to live channel on firebase, use with care
firebase --config firebase/firebase.json deploy
firebase-test: frontend ## Run firebase emulator for auth, hosting and datastore
firebase --config firebase/firebase.json emulators:start
.PHONY: firebase-deploy firebase-test frontend
# --- Release -------------------------------------------------------------------
release: nexttag ## Tag and release binaries for different OS on GitHub release
git tag $(NEXTTAG)
git push origin $(NEXTTAG)
goreleaser release --rm-dist
nexttag:
$(eval NEXTTAG := $(shell $(NEXTTAG_CMD)))
.PHONY: nexttag release
define NEXTTAG_CMD
{ git tag --list --merged HEAD --sort=-v:refname; echo v0.0.0; }
| grep -E "^v?[0-9]+.[0-9]+.[0-9]+$$"
| head -n1
| awk -F . '{ print $$1 "." $$2 "." $$3 + 1 }'
endef
# --- Utilities ----------------------------------------------------------------
COLOUR_NORMAL = $(shell tput sgr0 2>/dev/null)
COLOUR_RED = $(shell tput setaf 1 2>/dev/null)
COLOUR_GREEN = $(shell tput setaf 2 2>/dev/null)
COLOUR_WHITE = $(shell tput setaf 7 2>/dev/null)
help:
@awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[A-Za-z0-9%_-]+$$/ { printf "$(COLOUR_WHITE)%-25s$(COLOUR_NORMAL)%s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
$(O):
@mkdir -p $@
.PHONY: help
define nl
endef
ifndef ACTIVE_HERMIT
$(eval $(subst \n,$(nl),$(shell bin/hermit env -r | sed 's/^\(.*\)$$/export \1\\n/')))
endif
# Ensure make version is gnu make 3.82 or higher
ifeq ($(filter undefine,$(value .FEATURES)),)
$(error Unsupported Make version. \
$(nl)Use GNU Make 3.82 or higher (current: $(MAKE_VERSION)). \
$(nl)Activate 🐚 hermit with `. bin/activate-hermit` and run again \
$(nl)or use `bin/make`)
endif