-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (47 loc) · 2.55 KB
/
Makefile
File metadata and controls
62 lines (47 loc) · 2.55 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
.PHONY: all build install clean test test-cov lint fmt vet generate openapi-pull tidy run release-snapshot help
GO ?= go
BINARY ?= zd
DIST ?= ./dist
PKG := github.com/hackath0r/zd-cli
LDFLAGS := -s -w \
-X $(PKG)/internal/version.Version=$(shell git describe --tags --always --dirty 2>/dev/null || echo dev) \
-X $(PKG)/internal/version.Commit=$(shell git rev-parse --short HEAD 2>/dev/null || echo none) \
-X $(PKG)/internal/version.Date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
all: lint test build
build: ## Build the zd binary into the current directory
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/zd
install: ## Install zd to GOBIN
$(GO) install -trimpath -ldflags "$(LDFLAGS)" ./cmd/zd
generate: ## Regenerate the OpenAPI client from api/openapi.yaml
$(GO) generate ./internal/zenduty/...
openapi-pull: ## Pull and normalize the latest OpenAPI spec from apidocs.zenduty.com
@curl -fsSL https://apidocs.zenduty.com/openapi.json -o api/openapi.json
@$(GO) run ./internal/tools/json2yaml api/openapi.json api/openapi.yaml
@rm api/openapi.json
@$(GO) run ./internal/tools/normalize-spec api/openapi.yaml api/openapi.yaml
@echo "OpenAPI spec refreshed and normalized; run 'make generate' next."
test: ## Run unit tests
$(GO) test -race -count=1 ./...
test-cov: ## Run tests with coverage report (HTML + handwritten-only summary)
$(GO) test -race -count=1 -coverprofile=coverage.txt -covermode=atomic ./...
@grep -v '\.gen\.go:' coverage.txt | grep -v 'tools/json2yaml\|tools/normalize-spec' > coverage-handwritten.txt
@echo "--- handwritten code coverage ---"
@$(GO) tool cover -func=coverage-handwritten.txt | tail -1
$(GO) tool cover -html=coverage.txt -o coverage.html
lint: ## Run golangci-lint
@command -v golangci-lint >/dev/null 2>&1 || { echo >&2 "golangci-lint not installed; see https://golangci-lint.run/"; exit 1; }
golangci-lint run ./...
fmt: ## Format code
$(GO) fmt ./...
@command -v goimports >/dev/null 2>&1 && goimports -w -local $(PKG) . || true
vet: ## Run go vet
$(GO) vet ./...
tidy: ## go mod tidy
$(GO) mod tidy
release-snapshot: ## Build a local goreleaser snapshot
@command -v goreleaser >/dev/null 2>&1 || { echo >&2 "goreleaser not installed"; exit 1; }
goreleaser release --clean --snapshot --skip=publish
clean: ## Remove build artifacts
rm -rf $(DIST) $(BINARY) ximr coverage.txt coverage-handwritten.txt coverage.html cover.out
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'