Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (70 loc) · 2.06 KB
/
Copy pathMakefile
File metadata and controls
85 lines (70 loc) · 2.06 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
8000
div>
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
BINARY := linko
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
.PHONY: all
all: verify build
## deps: download modules and write go.sum
.PHONY: deps
deps:
go mod tidy
## build: compile ./linko for the current platform
.PHONY: build
build:
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) .
## install: build and install into $GOPATH/bin
.PHONY: install
install:
go install -trimpath -ldflags "$(LDFLAGS)" .
## test: run the full test suite
.PHONY: test
test:
go test ./... -count=1
## race: run the tests with the race detector
.PHONY: race
race:
go test ./... -race -count=1
## cover: run tests and print per-package coverage
.PHONY: cover
cover:
go test ./... -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out | tail -n 20
## e2e: full end-to-end test against a real Cloudflare account
.PHONY: e2e
e2e:
./scripts/e2e-test.sh
## verify: fmt check + vet + tests (run this before committing)
.PHONY: verify
verify: fmt-check vet test
.PHONY: fmt
fmt:
gofmt -s -w .
.PHONY: fmt-check
fmt-check:
@out=$$(gofmt -s -l .); \
if [ -n "$$out" ]; then echo "gofmt needed for:"; echo "$$out"; exit 1; fi
.PHONY: vet
vet:
go vet ./...
## release: cross-compile archives into dist/
.PHONY: release
release:
@rm -rf dist && mkdir -p dist
@for target in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64; do \
os=$${target%/*}; arch=$${target#*/}; \
ext=""; [ "$$os" = "windows" ] && ext=".exe"; \
echo "building $$os/$$arch"; \
GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags "$(LDFLAGS)" -o dist/$(BINARY)$$ext . || exit 1; \
if [ "$$os" = "windows" ]; then \
(cd dist && zip -q $(BINARY)_$(VERSION)_$${os}_$${arch}.zip $(BINARY)$$ext && rm $(BINARY)$$ext); \
else \
(cd dist && tar -czf $(BINARY)_$(VERSION)_$${os}_$${arch}.tar.gz $(BINARY) && rm $(BINARY)); \
fi; \
done
@ls -1 dist
## clean: remove build artefacts
.PHONY: clean
clean:
rm -rf dist coverage.out $(BINARY)
.PHONY: help
help:
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/^## //'