Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (70 loc) · 3.62 KB
/
Copy pathMakefile
File metadata and controls
92 lines (70 loc) · 3.62 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
# ynr: your named reporting.
#
# make check everything CI checks: formatting, vet, lint and tests with the race detector,
# for ynr, the Go spool exporter and the npm spool exporter
# make js install and build the npm spool exporter (spoolexporter/js)
# make build the slim build into bin/ynr (no cgo), plus linux builds for images
# make full the full build, with DuckDB (cgo), into bin/ynr-full
# make install the full build into ~/.ynr/bin/ynr (INSTALL_DIR to change it)
# make generate the dashboard's templates into Go
# make test the tests
# make fmt format Go and Terraform
# make help this text
VERSION ?= $(shell git describe --tags --match 'v*' --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X github.com/eyelock/ynr.Version=$(VERSION)
# Go modules in this repository: ynr, and the spool exporter the other tools import.
MODULES := . spoolexporter
# The npm spool exporter.
JS := spoolexporter/js
.PHONY: check build full install test vet lint fmt fmt-check slim-check generate generate-check help clean js js-test
check: fmt-check generate-check vet lint slim-check js js-test test
# The dashboard's templ templates, generated into Go and committed (ADR-005).
TEMPL := go run github.com/a-h/templ/cmd/templ@v0.3.1070
generate:
$(TEMPL) generate -path internal/ui
generate-check:
@$(TEMPL) generate -path internal/ui >/dev/null 2>&1
@git diff --quiet -- 'internal/ui/*_templ.go' || { echo "generated templates are stale: run make generate and commit"; git diff --stat -- 'internal/ui/*_templ.go'; exit 1; }
help:
@sed -n '2,/^$$/p' Makefile | sed -e 's/^# \{0,1\}//'
build:
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynr ./cmd/ynr
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynr-linux-arm64 ./cmd/ynr
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ynr-linux-amd64 ./cmd/ynr
full:
CGO_ENABLED=1 go build -tags full -trimpath -ldflags "$(LDFLAGS)" -o bin/ynr-full ./cmd/ynr
INSTALL_DIR ?= $(HOME)/.ynr/bin
# Copy to a temporary name, then rename over the old binary, as ynh, ynf and ynm do. Overwriting a
# binary in place keeps the same file, and on macOS the kernel's cached code-signature check for it
# can go stale: the next launch is killed with SIGKILL (exit 137) and no message.
install: full
@mkdir -p $(INSTALL_DIR)
cp bin/ynr-full $(INSTALL_DIR)/.ynr.tmp && mv -f $(INSTALL_DIR)/.ynr.tmp $(INSTALL_DIR)/ynr
@$(INSTALL_DIR)/ynr version
# Each module's tests, and ynr's again as the full build (ADR-001).
test:
@for m in $(MODULES); do (cd $$m && go test -race -count=1 ./...) || exit 1; done
go test -race -count=1 -tags full ./...
vet:
@for m in $(MODULES); do (cd $$m && go vet ./...) || exit 1; done
go vet -tags full ./...
lint:
@for m in $(MODULES); do (cd $$m && golangci-lint run ./...) || exit 1; done
golangci-lint run --build-tags full ./...
# The slim build must build without cgo and never link DuckDB.
slim-check:
CGO_ENABLED=0 go build -o /dev/null ./cmd/ynr
@if go list -deps ./cmd/ynr | grep -q duckdb; then echo "the slim build links DuckDB"; exit 1; fi
# Built before the Go tests, which run it to prove ynr reads what it writes.
js:
cd $(JS) && npm ci --no-audit --no-fund && npm run build
js-test:
cd $(JS) && npm run typecheck && npm test
fmt:
gofmt -w .
terraform fmt -recursive infra
fmt-check:
@out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi
@terraform fmt -check -recursive infra || { echo "terraform fmt needed: run make fmt"; exit 1; }
clean:
rm -rf bin $(JS)/dist $(JS)/node_modules