-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (58 loc) · 2.07 KB
/
Copy pathMakefile
File metadata and controls
70 lines (58 loc) · 2.07 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
BINARY := licscan
PKG := github.com/codelake-dev/licscan
CMD := ./cmd/licscan
BIN_DIR := ./bin
INSTALL_DIR := $(shell go env GOPATH)/bin
# Strip the leading 'v' from git-describe output — internal/version.Short()
# adds it back. Releasing v0.10.0 → ldflags Version=0.10.0 → Short() = "v0.10.0".
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//' || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X $(PKG)/internal/version.Version=$(VERSION) \
-X $(PKG)/internal/version.Commit=$(COMMIT) \
-X $(PKG)/internal/version.BuildDate=$(BUILD_DATE)
.PHONY: all
all: lint test build
.PHONY: build
build:
mkdir -p $(BIN_DIR)
go build -trimpath -ldflags '$(LDFLAGS)' -o $(BIN_DIR)/$(BINARY) $(CMD)
.PHONY: install
install:
go install -trimpath -ldflags '$(LDFLAGS)' $(CMD)
.PHONY: test
test:
go test ./... -race -count=1
.PHONY: cover
cover:
go test ./... -race -coverprofile=coverage.out -covermode=atomic
go tool cover -func=coverage.out | tail -1
@echo "HTML report: go tool cover -html=coverage.out -o coverage.html"
.PHONY: lint
lint:
@which golangci-lint > /dev/null || (echo "golangci-lint not installed: https://golangci-lint.run/usage/install/"; exit 1)
# 'config verify' catches schema errors that 'run' silently ignores
# (e.g. unknown gosec rule IDs). Both must pass for CI to be green.
golangci-lint config verify
golangci-lint run ./...
.PHONY: fmt
fmt:
gofmt -s -w .
.PHONY: tidy
tidy:
go mod tidy
.PHONY: clean
clean:
rm -rf $(BIN_DIR) coverage.out coverage.html dist/
.PHONY: help
help:
@echo "Targets:"
@echo " build Build the binary into $(BIN_DIR)/$(BINARY)"
@echo " install go install into $(INSTALL_DIR)"
@echo " test Run tests with race detector"
@echo " cover Run tests with coverage report"
@echo " lint Run golangci-lint config-verify + run"
@echo " fmt Format all Go source"
@echo " tidy go mod tidy"
@echo " clean Remove build artefacts"