-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (98 loc) · 3.42 KB
/
Copy pathMakefile
File metadata and controls
116 lines (98 loc) · 3.42 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
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.DEFAULT_GOAL := all
################################################################################
# Configurable variables
-include .env
GOOS ?= ""
GOARCH ?= ""
CGO_ENABLED ?= 0
################################################################################
# Functions
define INFO
@echo -e "\e[32m----- $(1)\e[0m"
endef
################################################################################
# All
all: build
.PHONY: all
################################################################################
# Dependencies
vendor: go.mod go.sum
@$(call INFO,"Tidying Go modules")
go mod tidy
@$(call INFO,"Vendoring Go modules")
go mod vendor
tools/go-licenses:
@$(call INFO,"Installing tool $(shell basename $@)")
GOBIN=$$(realpath $$(dirname $@)) go install github.com/google/go-licenses@v1.6.0
tools/golangci-lint:
@$(call INFO,"Installing tool $(shell basename $@)")
GOBIN=$$(realpath $$(dirname $@)) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
################################################################################
# Linters (and checks)
lint: lint-go check-licenses
.PHONY: lint
lint-go: vendor tools/golangci-lint
@$(call INFO,"Linting Go")
./tools/golangci-lint run -v
.PHONY: lint-go
check-licenses: tools/go-licenses vendor
@$(call INFO,"Checking third-party licenses")
./tools/go-licenses check ./... --include_tests --disallowed_types unknown,forbidden,restricted
.PHONY: check-licenses
################################################################################
# Generators
generate: cmd/fleeting-plugin-proxmox/licenses.txt
.PHONY: generate
cmd/fleeting-plugin-proxmox/licenses.txt: tools/go-licenses vendor
$(eval LICENSES_DIR := $(shell mktemp -d))
echo -e "" > $@;
@$(call INFO,"Saving licenses")
./tools/go-licenses save ./... --include_tests --force --save_path "${LICENSES_DIR}"
@$(call INFO,"Generating $@")
for FILE_PATH in $$(find "${LICENSES_DIR}" -type f | LC_ALL=C sort); do \
echo -e "$${FILE_PATH#${LICENSES_DIR}/}:\n" >> $@; \
while read -r LINE; do \
echo " $$LINE" >> $@; \
done < $$FILE_PATH; \
echo -e "" >> $@; \
done
@$(call INFO,"Removing temporary directory")
rm -rf "${LICENSES_DIR}"
################################################################################
# Builds
build: bin/fleeting-plugin-proxmox
.PHONY: build
bin/fleeting-plugin-proxmox: vendor $(shell find cmd -name *.go)
@$(call INFO,"Building $@")
@mkdir -p $(shell dirname $@)
GOOS="${GOOS}" GOARCH="${GOARCH}" CGO_ENABLED="${CGO_ENABLED}" go build -ldflags "-w -extldflags '-static'" -o $@ ./cmd/fleeting-plugin-proxmox
################################################################################
# Tests
test: unit-test integration-test
.PHONY: test
unit-test: vendor
@$(call INFO,"Running unit tests")
go test -v ./cmd/...
.PHONY: unit-test
integration-test: bin/fleeting-plugin-proxmox
@$(call INFO,"Running integration tests")
go test -v $(shell go list ./test/integration) \
-timeout 30m \
-plugin-binary-path="$(PWD)/bin/fleeting-plugin-proxmox" \
-config-path="$(PWD)/config.json"
.PHONY: integration-test
################################################################################
# Cleanup
clean:
@$(call INFO,"Cleaning")
rm -rf \
bin \
tools/go-licenses \
tools/golangci-lint \
vendor
.PHONY: clean