| 1 | # Go + Rastrillo TodoMVC. See README.md. |
| 2 | # |
| 3 | # GOCACHE stays at its default (a shared machine rule): COLD=1 forces a |
| 4 | # from-scratch compile with -a instead of deleting the cache. |
| 5 | |
| 6 | APP := todo-go-rastrillo |
| 7 | ACCOUNT := bfj |
| 8 | VERSION ?= $(shell git rev-parse --short HEAD) |
| 9 | LDFLAGS := -s -w -X 'amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)' |
| 10 | COLDFLAG := $(if $(COLD),-a,) |
| 11 | RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo |
| 12 | MESSAGE ?= Deploy $(VERSION) |
| 13 | |
| 14 | # The string constant make bump edits: in handlers.go, beside GET /. |
| 15 | BUMP_FILE := internal/todo/handlers.go |
| 16 | BUMP_FROM := const notFoundTitle = "That item is not in your list" |
| 17 | BUMP_TO := const notFoundTitle = "That item is not in your list." |
| 18 | |
| 19 | export CGO_ENABLED = 0 |
| 20 | |
| 21 | .PHONY: build build-arm64 test perf migration-check clean clean-deps bump unbump deploy |
| 22 | |
| 23 | build: |
| 24 | go build $(COLDFLAG) -trimpath -ldflags="$(LDFLAGS)" -o dist/app ./cmd/todo |
| 25 | |
| 26 | build-arm64: |
| 27 | GOOS=linux GOARCH=arm64 go build $(COLDFLAG) -trimpath -ldflags="$(LDFLAGS)" -o dist/app-linux-arm64 ./cmd/todo |
| 28 | |
| 29 | # Rastrillo's test runner: go test plus each package's time budget. |
| 30 | test: |
| 31 | go vet ./... |
| 32 | test -z "$$(gofmt -l .)" || { gofmt -l .; exit 1; } |
| 33 | $(RASTRILLO) budget test ./... |
| 34 | $(RASTRILLO) migration check |
| 35 | |
| 36 | # Every GET screen at 150ms to first byte, cold boot at 500ms. Serial |
| 37 | # and uncached, because a measurement taken beside other work isn't one. |
| 38 | perf: |
| 39 | $(RASTRILLO) budget test -no-time -require TestPerfScreens,TestPerfBoot -tags perf -count=1 -p 1 -parallel 1 -run '^TestPerf' ./... |
| 40 | |
| 41 | clean: |
| 42 | rm -rf dist |
| 43 | |
| 44 | # Go keeps compiled packages in the shared GOCACHE, which this target |
| 45 | # leaves alone; `make build-arm64 COLD=1` recompiles everything with -a. |
| 46 | clean-deps: clean |
| 47 | |
| 48 | bump: |
| 49 | sed -i 's/^$(BUMP_FROM)$$/$(BUMP_TO)/' $(BUMP_FILE) |
| 50 | grep -qxF '$(BUMP_TO)' $(BUMP_FILE) |
| 51 | |
| 52 | unbump: |
| 53 | sed -i 's/^$(BUMP_TO)$$/$(BUMP_FROM)/' $(BUMP_FILE) |
| 54 | grep -qxF '$(BUMP_FROM)' $(BUMP_FILE) |
| 55 | |
| 56 | deploy: |
| 57 | carlos deploy --account $(ACCOUNT) --app $(APP) --target linux-arm64 --message "$(MESSAGE)" dist/app-linux-arm64 |
| 58 | |