-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
113 lines (93 loc) · 3.41 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
.DEFAULT_GOAL := build
export CGO_ENABLED = 0
export GO111MODULE := on
GOFILES_NOVENDOR=$(shell find . -type f -name '*.go' | grep -v vendor)
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
OUT_D?=$(shell pwd)/builds
DOCS_OUT?=$(shell pwd)/docs/subcommands
# Want to test verbosely? (i.e. see what test is failing?) Run like:
# make test TEST_FLAGS="-v [optionally other flags]"
TEST_DIRS := $(shell go list ./... | \
grep -v /commands/container-registry | \
grep -v /commands/dbaas/mongo | \
grep -v /commands/logging-service | \
grep -v /commands/dataplatform) # All commands except ...
TEST_FLAGS := "-cover"
.PHONY: utest
utest:
@echo "--- Run unit tests ---"
@go test $(TEST_FLAGS) $(TEST_DIRS)
# Note about test file tagging:
# `//go:build integration` was introduced in Go 1.17
# `// +build integration` is still maintained for compatibility reasons
# `go fmt` still maintains these lines, if one is removed. If it stops this behaviour, then we can remove them
.PHONY: test
test:
@echo "--- Run bats-core, integration and unit tests ---"
@test/run.sh # bats-core tests and other
@go test $(TEST_FLAGS) -tags=integration $(TEST_DIRS)
.PHONY: mocks
mocks:
@echo "--- Update mocks ---"
@echo "--- Ensure gomock is up to date. Run: 'go install github.com/golang/mock/[email protected]' ---"
@tools/mocks.sh && echo "DONE"
.PHONY: docs generate-docs
docs generate-docs:
@echo "--- Purging docs ---"
rm -rf docs/subcommands
touch docs/summary.md
rm docs/summary.md
@echo "--- Regenerating docs ---"
@go run tools/doc.go
.PHONY: gofmt_check
gofmt_check:
@echo "--- Ensure code adheres to gofmt and list files whose formatting differs(vendor directory excluded) ---"
@if [ "$(shell echo $$(gofmt -l ${GOFILES_NOVENDOR}))" != "" ]; then (echo "Format files: $(shell echo $$(gofmt -l ${GOFILES_NOVENDOR})) Hint: use \`make gofmt\`"; exit 1); fi
@echo "DONE"
.PHONY: gofmt
gofmt:
@echo "--- Ensure code adheres to gofmt and change files accordingly(vendor directory excluded) ---"
@gofmt -w ${GOFILES_NOVENDOR} && echo "DONE"
.PHONY: goimports
goimports:
@echo "--- Ensure code adheres to goimports and change files accordingly(vendor directory excluded) ---"
@goimports -w ${GOFILES_NOVENDOR} && echo "DONE"
.PHONY: vendor_check
vendor_check:
@govendor status
.PHONY: vendor
vendor:
@echo "--- Update vendor dependencies ---"
@go mod vendor
@go mod tidy
@echo "DONE"
BINARY_NAME ?= ionosctl # To install with a custom name, e.g. `io`, do `make install BINARY_NAME=io`
.PHONY: build
build: vendor
@echo "--- Building ionosctl via go build ---"
@OUT_D=${OUT_D} GOOS=$(GOOS) GOARCH=$(GOARCH) tools/build.sh build
@echo "built ${OUT_D}/ionosctl_${GOOS}_${GOARCH}"
@echo "DONE"
.PHONY: install
install: vendor
@echo "--- Install ionosctl via go install ---"
@GOOS=$(GOOS) GOARCH=$(GOARCH) tools/build.sh install
@echo "DONE"
.PHONY: clean
clean:
@echo "--- Remove built / installed artifacts ---"
@go clean -i
@rm -rf builds
@echo "DONE"
.PHONY: help
help:
@echo "TARGETS: "
@echo " - utest:\tRun unit tests"
@echo " - test:\tRun integration and unit tests (CI Target)"
@echo " - mocks:\tUpdate mocks. WARNING: Do not interrupt early!"
@echo " - gofmt:\tFormat code to adhere to gofmt [gofmt_check for checking only]"
@echo " - vendor:\tUpdate vendor dependencies. [vendor_check for checking only]"
@echo " - goimports:\tFormat, sort imports"
@echo " - docs:\tRegenerate docs"
@echo " - build/install/clean"