-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
185 lines (130 loc) · 5.83 KB
/
Makefile
File metadata and controls
185 lines (130 loc) · 5.83 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Run `make help` to display help
.DEFAULT_GOAL := $(or $(EVY_DEFAULT_GOAL),help)
# --- Global -------------------------------------------------------------------
O = out
COVERAGE = 80
VERSION ?= $(shell git describe --tags --dirty --always)
GOFILES = $(shell find . -name '*.go')
all: build test lint tiny test-tiny check-coverage sh-lint check-prettier check-evy-fmt frontend ## 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 fmt
test -z "$$(git status --porcelain -- go.mod go.sum $(GOFILES))" || { 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 evy binaries
go build -o $(O) -ldflags='$(GO_LDFLAGS)' $(CMDS)
install: ## Build and install binaries in $GOBIN
go install -ldflags='$(GO_LDFLAGS)' $(CMDS)
# Use `go version` to ensure the right go version is installed when using tinygo.
go-version:
go version
# Optimise tinygo output for size, see https://www.fermyon.com/blog/optimizing-tinygo-wasm
tiny: go-version | $(O) ## Build for tinygo / wasm
tinygo build -o frontend/evy.wasm -target wasm -no-debug -ldflags='$(GO_LDFLAGS)' -stack-size=128kb ./pkg/wasm
cp -f $$(tinygo env TINYGOROOT)/targets/wasm_exec.js frontend/
tidy: ## Tidy go modules with "go mod tidy"
go mod tidy
fmt: ## Format all go files with gofumpt, a stricter gofmt
gofumpt -w $(GOFILES)
clean::
-rm -f frontend/evy.wasm
-rm -f frontend/wasm_exec.js
.PHONY: build go-version install tidy tiny
# --- Test ---------------------------------------------------------------------
COVERFILE = $(O)/coverage.txt
test: | $(O) ## Run non-tinygo tests and generate a coverage file
go test -coverprofile=$(COVERFILE) ./...
test-tiny: go-version | $(O) ## Run tinygo tests
tinygo test ./...
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 test-tiny
# --- Lint ---------------------------------------------------------------------
EVY_FILES = $(shell find frontend/courses -name '*.evy')
lint: ## Lint go source code
golangci-lint run
evy-fmt: ## Format evy sample code
go run . fmt --write $(EVY_FILES)
check-evy-fmt:
go run . fmt --check $(EVY_FILES)
.PHONY: check-evy-fmt evy-fmt lint
# --- frontend -----------------------------------------------------------------
NODELIB = .hermit/node/lib
frontend: tiny | $(O) ## Build frontend, typically iterate with npm and inside frontend
rm -rf $(O)/public
cp -r frontend $(O)/public
frontend-serve: frontend ## Build frontend and serve on free port
servedir $(O)/public
prettier: | $(NODELIB) ## Format frontend code with prettier
npx -y prettier --write frontend
check-prettier: | $(NODELIB) ## Ensure frontend code is formatted with prettier
npx -y prettier --check frontend
$(NODELIB):
@mkdir -p $@
.PHONY: check-prettier frontend frontend-serve prettier
# --- firebase -----------------------------------------------------------------
firebase-deploy-prod: firebase-public ## Deploy to live channel on firebase, use with care!
./firebase/deploy live
firebase-deploy: firebase-public ## Deploy to dev (or other) channel on firebase
./firebase/deploy
firebase-emulate: firebase-public ## Run firebase emulator for auth, hosting and datastore
firebase --config firebase/firebase.json emulators:start
firebase-public: frontend
rm -rf firebase/public
cp -r $(O)/public firebase
.PHONY: firebase-deploy firebase-deploy-prod firebase-emulate firebase-public
# --- scripts ------------------------------------------------------------------
SCRIPTS = firebase/deploy .github/scripts/app_token
sh-lint: ## Lint script files with shellcheck and shfmt
shellcheck $(SCRIPTS)
shfmt --diff $(SCRIPTS)
sh-fmt: ## Format script files
shfmt --write $(SCRIPTS)
.PHONY: sh-fmt sh-lint
# --- Release -------------------------------------------------------------------
release: nexttag ## Tag and release binaries for different OS on GitHub release
git tag $(NEXTTAG)
git push origin $(NEXTTAG)
[ -z "$(CI)" ] || GITHUB_TOKEN=$$(.github/scripts/app_token) || exit 1; \
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