Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (97 loc) · 3.97 KB
/
Copy pathMakefile
File metadata and controls
116 lines (97 loc) · 3.97 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
# plex-sync developer tasks.
#
# Everything here works with stock Go 1.24+ and no CGO, because the SQLite
# driver is pure Go.
BINARY := plex-sync
PKG := github.com/TheIntroDB/plex-sync
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 $(PKG)/internal/buildinfo.Version=$(VERSION) \
-X $(PKG)/internal/buildinfo.Commit=$(COMMIT) \
-X $(PKG)/internal/buildinfo.Date=$(DATE)
# The formatter, pinned. gofumpt is gofmt plus the rules gofmt leaves to taste,
# and it is what the source in this repository is written in: 'make fmt-check'
# has to agree with what a contributor's editor produces, so both read this
# version rather than whatever happens to be on PATH.
GOFUMPT_VERSION := v0.12.0
GOFUMPT ?= $(shell command -v gofumpt 2>/dev/null || echo $(shell go env GOPATH)/bin/gofumpt)
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: ## Build the binary into ./bin
go build -trimpath -ldflags "$(LDFLAGS)" -o bin/$(BINARY) .
.PHONY: install
install: ## Install into GOPATH/bin
go install -trimpath -ldflags "$(LDFLAGS)" .
.PHONY: test
test: ## Run all tests
go test ./...
.PHONY: test-race
test-race: ## Run all tests with the race detector
go test -race ./...
.PHONY: test-live
test-live: ## Run the tests that need a copy of a real Plex database
./scripts/live-e2e.sh
# The platforms CI runs are not interchangeable, and the tests have twice been
# green here while failing there: macOS passed while Linux and Windows failed,
# then macOS and Linux passed while Windows failed. These two targets check the
# other platforms from this one, so a red CI run is not the first news.
#
# test-linux runs the tests on Linux, which is the real thing on a Mac.
# vet-other only compiles the others, since there is no way to run Windows here,
# but that still catches a test that does not build on a platform, and it is the
# reason the windows-only test failure could have been seen before pushing.
DOCKER ?= docker
GOIMAGE ?= golang:1.27
.PHONY: test-linux
test-linux: ## Run the whole test suite on Linux, in a container
$(DOCKER) run --rm -v "$(CURDIR)":/src -w /src -e CGO_ENABLED=0 \
$(GOIMAGE) go test -count=1 ./...
.PHONY: vet-other
vet-other: ## Compile-check every released platform, test files included
@set -e; \
for target in windows/amd64 windows/arm64 darwin/arm64 freebsd/amd64 linux/arm; do \
printf ' %-16s' "$$target"; \
GOOS=$${target%%/*} GOARCH=$${target##*/} CGO_ENABLED=0 go vet ./... ; \
echo "ok"; \
done; \
echo "every released platform compiles"
.PHONY: cover
cover: ## Run tests and write coverage.html
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
.PHONY: fmt
fmt: ## Format all Go source with the pinned gofumpt
@command -v $(GOFUMPT) >/dev/null 2>&1 || { echo "$(GOFUMPT) is not installed; run 'make tools'"; exit 1; }
$(GOFUMPT) -w .
.PHONY: fmt-check
fmt-check: ## Fail if any Go source is not formatted
@command -v $(GOFUMPT) >/dev/null 2>&1 || { echo "$(GOFUMPT) is not installed; run 'make tools'"; exit 1; }
@unformatted="$$($(GOFUMPT) -l . | grep -v '^$$')"; \
if [ -n "$$unformatted" ]; then \
echo "::error::these files are not formatted:"; \
echo "$$unformatted"; \
echo; \
echo "run 'make fmt' to fix them"; \
exit 1; \
fi
@echo "formatting ok ($(GOFUMPT_VERSION))"
.PHONY: tools
tools: ## Install the pinned developer tools
go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
.PHONY: lint
lint: fmt-check ## Check formatting and run go vet
go vet ./...
.PHONY: tidy
tidy: ## Tidy the module
go mod tidy
.PHONY: snapshot
snapshot: ## Build all release targets without publishing
goreleaser release --snapshot --clean
.PHONY: run
run: build ## Build and start the terminal interface
./bin/$(BINARY)