forked from lox/apt-proxy
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (97 loc) · 3.43 KB
/
Copy pathMakefile
File metadata and controls
115 lines (97 loc) · 3.43 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
.DEFAULT_GOAL := help
GO ?= go
GOFLAGS ?= -trimpath
PKG := ./...
BINARY := apt-proxy
CMD_DIR := ./cmd/apt-proxy
DIST_DIR := dist
COVERAGE_OUT := coverage.out
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS ?= -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(DATE)
.PHONY: help
help:
@echo "Common targets:"
@echo " make build - build binary into ./$(DIST_DIR)/$(BINARY)"
@echo " make run - go run the daemon"
@echo " make test - run unit tests with -race -short"
@echo " make test-full - run all tests (including integration)"
@echo " make test-integration - run integration-tagged tests"
@echo " make test-isolation - rerun cross-Server isolation tests under -race -count=3"
@echo " make cover - generate coverage profile + summary"
@echo " make lint - run golangci-lint"
@echo " make fmt - run gofmt + goimports"
@echo " make vet - run go vet"
@echo " make tidy - go mod tidy"
@echo " make vuln - run govulncheck"
@echo " make docker - build local docker image"
@echo " make release-snap - goreleaser snapshot (no publish)"
@echo " make clean - remove build artifacts"
.PHONY: build
build:
mkdir -p $(DIST_DIR)
$(GO) build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(DIST_DIR)/$(BINARY) $(CMD_DIR)
.PHONY: run
run:
$(GO) run $(CMD_DIR)
.PHONY: test
test:
$(GO) test -race -short -count=1 $(PKG)
.PHONY: test-full
test-full:
$(GO) test -race -count=1 $(PKG)
.PHONY: test-integration
test-integration:
$(GO) test -tags=integration -race -count=1 -timeout=10m ./tests/integration/...
# test-isolation reruns the per-Server isolation suite with -race and
# -count=3 so flaky cross-Server bleed shows up locally and in CI. The
# unit-level cases in internal/cli/server_isolation_test.go run on the
# default tag; the matching integration cases (multi-server real-port
# tests in tests/integration/multi_server_test.go) require the
# `integration` tag.
.PHONY: test-isolation
test-isolation:
$(GO) test -race -count=3 -run 'Isolation|TwoServers' ./internal/...
$(GO) test -tags=integration -race -count=3 -run 'MultiServer' -timeout=5m ./tests/integration/...
.PHONY: cover
cover:
$(GO) test -race -short -count=1 -coverprofile=$(COVERAGE_OUT) -covermode=atomic $(PKG)
$(GO) tool cover -func=$(COVERAGE_OUT) | tail -n 1
.PHONY: lint
lint:
@which golangci-lint >/dev/null 2>&1 || { \
echo "golangci-lint not found; install: https://golangci-lint.run/welcome/install/"; \
exit 1; \
}
golangci-lint run --timeout=5m
.PHONY: fmt
fmt:
gofmt -s -w .
@which goimports >/dev/null 2>&1 && goimports -w . || true
.PHONY: vet
vet:
$(GO) vet $(PKG)
.PHONY: tidy
tidy:
$(GO) mod tidy
.PHONY: vuln
vuln:
@which govulncheck >/dev/null 2>&1 || $(GO) install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck $(PKG)
.PHONY: docker
docker:
docker build -t $(BINARY):$(VERSION) -f docker/Dockerfile .
.PHONY: release-snap
release-snap:
@which goreleaser >/dev/null 2>&1 || { \
echo "goreleaser not found; install: https://goreleaser.com/install/"; \
exit 1; \
}
goreleaser release --snapshot --clean
.PHONY: clean
clean:
rm -rf $(DIST_DIR) $(COVERAGE_OUT)