-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
99 lines (79 loc) · 2.07 KB
/
Makefile
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
BINDIR := bin/
ifeq ($(OS),Windows_NT)
BINNAME ?= hypper.exe
else
BINNAME ?= hypper
endif
INSTALL_PATH ?= /usr/local/bin
SHELL = /usr/bin/env bash
GIT_COMMIT = $(shell git rev-parse HEAD)
ifneq ($(GIT_TAG),)
GIT_TAG := $(GIT_TAG)
else
GIT_TAG = $(shell git describe --tags 2>/dev/null)
endif
# go option
PKG := ./...
PKGTESTS := $$(go list ./... | grep -v /third-party/)
TAGS :=
TESTS := .
TESTFLAGS :=
LDFLAGS := -w -s
GOFLAGS :=
LDFLAGS += -X github.com/rancher-sandbox/hypper/internal/version.version=${GIT_TAG}
LDFLAGS += -X github.com/rancher-sandbox/hypper/internal/version.gitCommit=${GIT_COMMIT}
LDFLAGS += $(EXT_LDFLAGS)
.PHONY: all
all: build
.PHONY: build
build: lint $(BINDIR)$(BINNAME)
# Rebuild the binary if any of these files change
SRC := $(shell find . -type f -name '*.go' -print) go.mod go.sum
$(BINDIR)$(BINNAME): $(SRC)
go build $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $(BINDIR)$(BINNAME) ./cmd/hypper
.PHONY: install
install: build
@install "$(BINDIR)$(BINNAME)" "$(INSTALL_PATH)/$(BINNAME)"
.PHONY: test
test: lint shellcheck build
test: TESTFLAGS += -race -v
test: test-style
test: test-unit
.PHONY: test-unit
test-unit:
@echo "==> Running unit tests <=="
go test $(GOFLAGS) -run $(TESTS) $(PKGTESTS) $(TESTFLAGS)
# Generate golden files used in unit tests
.PHONY: gen-test-golden
gen-test-golden:
gen-test-golden: PKGTESTS = ./cmd/hypper ./pkg/action ./pkg/chart ./internal/solver
gen-test-golden: TESTFLAGS = -update
gen-test-golden: test-unit
.PHONY: test-style
test-style:
@echo "==> Checking style <=="
golangci-lint run
.PHONY: coverage
coverage:
@echo "==> Running coverage tests <=="
go test $(GOFLAGS) -run $(TESTS) $(PKGTESTS) -coverprofile=coverage.out --covermode=atomic
.PHONY: lint
lint: fmt vet
.PHONY: vet
vet:
go vet ./...
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: license-check
license-check:
@scripts/license_check.sh
.PHONY: shellcheck
shellcheck:
@echo "==> Checking shell scripts <=="
shellcheck ./scripts/*
@echo "==> Done <=="
.PHONY: clean
clean:
rm $(BINDIR)$(BINNAME)
rmdir $(BINDIR)