Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
127 lines (91 loc) · 3.03 KB
/
Copy pathMakefile
File metadata and controls
127 lines (91 loc) · 3.03 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
117
118
119
120
121
122
123
124
125
126
127
export VERSION := $(shell git describe --tags --abbrev=0)
export COMMIT := $(shell git rev-parse --short HEAD)
export DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# derived variables
export
ifndef RELEASE
RELEASE_FLAG:=--snapshot
endif
GOLANGCI_LINT_BIN := ./bin/golangci-lint
GOLANGCI_LINT_VERSION := $(shell cat .golangci-lint-version)
TARGET := nwsctl
all: build
##################################
# Build targets
setup: setup-golangci-lint
setup-golangci-lint:
curl -sSfL https://golangci-lint.run/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
$(GOLANGCI_LINT_BIN):
@echo "golangci-lint is not installed. Please run 'make setup' to install it."
@exit 1
# Build binary for local environment
BUILD_LDFLAGS := -X main.commit=$(COMMIT) -X main.date=$(DATE)
define go-build
go build \
-ldflags "$(BUILD_LDFLAGS) $(1)" \
$(2) \
-o $@ \
./cmd/nwsctl
endef
build: ${TARGET}
${TARGET}:
$(call go-build,-X main.version=$(VERSION)-snapshot,)
build-coverage: ${TARGET}-cov
# Build binary instrumented for coverage measurement
${TARGET}-cov:
$(call go-build,-X main.version=$(VERSION)-snapshot-coverage,-cover)
build-release:
goreleaser release --clean --skip=publish ${RELEASE_FLAG}
# Build release binary
release: user-guide build-release
clean: coverage-clean test-clean
go clean
- rm nwsctl
make clean -C docs/user-guide
- rm -rf dist
##################################
# Document targets
# Create all docs
doc: user-guide
# Create user guide
user-guide:
make -C docs/user-guide
# Not wired into `check` yet: docs/README.md currently has known broken
# links (tracked separately) that would make this fail today.
docs-lint:
make -C docs lint
##################################
# License targets
# Collect license texts for all dependencies linked into the binary, into ./LICENSES
licenses:
GOTOOLCHAIN=$(shell go env GOVERSION) GOROOT=$(shell go env GOROOT) go run github.com/google/go-licenses@v1.6.0 save ./cmd/nwsctl --save_path=./LICENSES --force --ignore github.com/sony/niwashi
##################################
# Test targets
# Tests
test-clean:
go clean -testcache
lint:
$(GOLANGCI_LINT_BIN) run ./internal/... ./cmd/...
unit-test:
go test ./internal/... ./cmd/... --cover
e2e-test:
make -C test/e2e
check: lint unit-test e2e-test
##################################
# Analytics targets
coverage: coverage-report
go tool cover -func=.covdata/coverage.out | tail -1 | awk '{print "Total Coverage:",$$3}'
coverage-clean:
- rm -rf .covdata nwsctl-cov
coverage-unit:
mkdir -p .covdata/unit
go test -count=1 -cover ./internal/... ./cmd/... -args -test.gocoverdir=$(CURDIR)/.covdata/unit
coverage-e2e: build-coverage
mkdir -p .covdata/e2e
NWSCTL_BINARY=$(CURDIR)/${TARGET}-cov GOCOVERDIR=$(CURDIR)/.covdata/e2e make -C test/e2e
coverage-data: coverage-unit coverage-e2e
mkdir -p .covdata/merged
go tool covdata merge -i=.covdata/unit,.covdata/e2e -o=.covdata/merged
go tool covdata textfmt -i=.covdata/merged -o=.covdata/coverage.out
coverage-report: coverage-data
go tool cover -html=.covdata/coverage.out -o=.covdata/coverage.html