-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
87 lines (70 loc) · 3.31 KB
/
Copy pathMakefile
File metadata and controls
87 lines (70 loc) · 3.31 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
export CGO_ENABLED := 0
export GOEXPERIMENT := jsonv2
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION := v2.12.2
# Hugo is a tool dependency (see the tool directive in go.mod), so the version the site is built
# with is pinned there and needs nothing installed. HUGO overrides it with another binary.
HUGO ?= go tool hugo
# Port for docs-serve.
DOCS_PORT ?= 1313
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
REVISION := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
GOBUILDFLAGS := -trimpath -ldflags="-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)"
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: OUTPUT ?= bin/decolint
build: ## Build the decolint binary
go build $(GOBUILDFLAGS) -o $(OUTPUT) ./cmd/decolint
.PHONY: run
run: build ## Build and run the decolint binary
./bin/decolint $(ARGS)
.PHONY: test
test: ## Run all tests
go test ./...
.PHONY: coverage
coverage: ## Run tests and open an HTML coverage report
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html
.PHONY: lint
lint: ## Run all lint rules
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run
.PHONY: docs
docs: docs-content docs-syntax ## Build the documentation site into docs/public
$(HUGO) --source docs --minify
.PHONY: docs-serve
docs-serve: docs-content docs-syntax ## Serve the documentation site with live reload
# hugo server keeps the path of the configured baseURL, which would serve the site under
# /decolint/ and leave http://localhost:$(DOCS_PORT)/ a 404. Override it for local preview.
$(HUGO) server --source docs --port $(DOCS_PORT) --baseURL http://localhost:$(DOCS_PORT)/
.PHONY: docs-content
docs-content: ## Regenerate the rule pages, README-derived pages, and README rules table
go run ./cmd/docgen
.PHONY: docs-syntax
docs-syntax: ## Regenerate the syntax highlighting stylesheet
@mkdir -p docs/.generated/assets/css
@set -e; \
light=$$($(HUGO) gen chromastyles --style=github); \
dark=$$($(HUGO) gen chromastyles --style=github-dark); \
{ \
echo '/* Chroma syntax highlighting token colors.'; \
echo ' Generated by `make docs-syntax`; edit that target rather than this file. */'; \
echo; \
echo "$$light" | tail -n +2; \
echo '@media (prefers-color-scheme: dark) {'; \
echo ' /* github-dark omits token classes it colors the same as the default text color,'; \
echo ' so fall back to inheriting that color instead of the light style'"'"'s, which'; \
echo ' stays in effect below for every class the dark style does define. */'; \
echo "$$light" | tail -n +2 | grep -oE '\.chroma \.[A-Za-z0-9]+' | sort -u | sed 's/.*/ & { color: inherit }/'; \
echo "$$dark" | tail -n +2 | sed 's/^./ &/'; \
echo '}'; \
} > docs/.generated/assets/css/syntax.css
.PHONY: clean
clean: ## Remove build artifacts
rm -rf bin coverage.out coverage.html docs/public docs/resources docs/.generated docs/.hugo_build.lock .hugo_build.lock
.PHONY: install
install: ## Install the decolint binary to GOPATH/bin
go install $(GOBUILDFLAGS) ./cmd/decolint