-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
153 lines (115 loc) · 4.37 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
SHELL = /bin/bash
default: build
# #### GO Binary Management ####
.PHONY: deps-go-binary deps-counterfeiter deps-ginkgo deps-golangci-lint
GO_VERSION := $(shell go version)
GO_VERSION_REQUIRED = go1.19
GO_VERSION_MATCHED := $(shell go version | grep $(GO_VERSION_REQUIRED))
deps-go-binary:
ifndef GO_VERSION
$(error Go not installed)
endif
ifndef GO_VERSION_MATCHED
$(error Required Go version is $(GO_VERSION_REQUIRED), but was $(GO_VERSION))
endif
@:
HAS_COUNTERFEITER := $(shell command -v counterfeiter;)
HAS_GINKGO := $(shell command -v ginkgo;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_SHELLCHECK := $(shell command -v shellcheck;)
PLATFORM := $(shell uname -s)
# If go get is run from inside the project directory it will add the dependencies
# to the go.mod file. To avoid that we import from another directory
deps-counterfeiter: deps-go-binary
ifndef HAS_COUNTERFEITER
go install github.com/maxbrunsfeld/counterfeiter/v6@latest
endif
deps-ginkgo: deps-go-binary
ifndef HAS_GINKGO
go install github.com/onsi/ginkgo/ginkgo@latest
endif
deps-golangci-lint: deps-go-binary
ifndef HAS_GOLANGCI_LINT
ifeq ($(PLATFORM), Darwin)
brew install golangci-lint
endif
ifeq ($(PLATFORM), Linux)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
endif
endif
deps-shellcheck:
ifndef HAS_SHELLCHECK
ifeq ($(PLATFORM), Darwin)
brew install shellcheck
endif
ifeq ($(PLATFORM), Linux)
apt-get update && apt-get install -y shellcheck
endif
endif
# #### CLEAN ####
.PHONY: clean
clean: deps-go-binary
rm -rf build/*
go clean --modcache
# #### DEPS ####
.PHONY: deps deps-counterfeiter deps-ginkgo deps-modules
deps-modules: deps-go-binary
go mod download
deps: deps-modules deps-counterfeiter deps-ginkgo
# #### BUILD ####
.PHONY: build
SRC = $(shell find . -name "*.go" | grep -v "_test\." )
VERSION := $(or $(VERSION), dev)
LDFLAGS="-X github.com/vmware-labs/marketplace-cli/v2/cmd.version=$(VERSION)"
build/mkpcli: $(SRC)
go build -o build/mkpcli -ldflags ${LDFLAGS} ./main.go
build/mkpcli-darwin-amd64: $(SRC)
GOARCH=amd64 GOOS=darwin go build -o build/mkpcli-darwin-amd64 -ldflags ${LDFLAGS} ./main.go
build/mkpcli-darwin-arm64: $(SRC)
GOARCH=arm64 GOOS=darwin go build -o build/mkpcli-darwin-arm64 -ldflags ${LDFLAGS} ./main.go
build/mkpcli-linux-amd64: $(SRC)
GOARCH=amd64 GOOS=linux go build -o build/mkpcli-linux-amd64 -ldflags ${LDFLAGS} ./main.go
build/mkpcli-windows-amd64.exe: $(SRC)
GOARCH=amd64 GOOS=windows go build -o build/mkpcli-windows-amd64.exe -ldflags ${LDFLAGS} ./main.go
build: deps build/mkpcli
build-all: build/mkpcli-darwin-amd64 build/mkpcli-darwin-arm64 build/mkpcli-linux-amd64 build/mkpcli-windows-amd64
release: build/mkpcli-darwin-amd64 build/mkpcli-darwin-arm64 build/mkpcli-linux-amd64 build/mkpcli-windows-amd64.exe
mkdir -p release
cp -f build/mkpcli-darwin-amd64 release/mkpcli && tar czvf release/mkpcli-darwin-amd64.tgz -C release mkpcli
cp -f build/mkpcli-darwin-arm64 release/mkpcli && tar czvf release/mkpcli-darwin-arm64.tgz -C release mkpcli
cp -f build/mkpcli-linux-amd64 release/mkpcli && tar czvf release/mkpcli-linux-amd64.tgz -C release mkpcli
cp -f build/mkpcli-windows-amd64.exe release/mkpcli.exe && zip -j release/mkpcli-windows-amd64.zip release/mkpcli.exe
rm release/mkpcli release/mkpcli.exe
build-image: build/mkpcli-linux
docker build . --tag harbor-repo.vmware.com/tanzu_isv_engineering/mkpcli:$(VERSION)
# #### TESTS ####
.PHONY: lint test test-features test-units
test-units: deps
ginkgo -r -skipPackage test .
test-features: deps
ginkgo -r test/features
test-external: deps
ifndef CSP_API_TOKEN
$(error CSP_API_TOKEN must be defined to run external tests)
else
ginkgo -r test/external
endif
test-external-with-strict-decoding: deps
ifndef CSP_API_TOKEN
$(error CSP_API_TOKEN must be defined to run external tests)
else
MKPCLI_STRICT_DECODING=true ginkgo -r test/external
endif
test: deps lint test-units test-features test-external test-external-with-strict-decoding
lint: lint-go lint-bash
lint-go: deps-golangci-lint
golangci-lint run
BASH_SRC = $(shell find . -name "*.sh" )
lint-bash: $(BASH_SRC) deps-shellcheck
shellcheck $(BASH_SRC)
# #### DEVOPS ####
.PHONY: set-pipeline
set-pipeline: ci/pipeline.yaml
fly -t tie set-pipeline --config ci/pipeline.yaml --pipeline marketplace-cli