forked from banzaicloud/cloudinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (64 loc) · 2.53 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
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
OS = $(shell uname | tr A-Z a-z)
# Project variables
BUILD_PACKAGE ?= ./cmd/cloudinfo
BINARY_NAME ?= cloudinfo
DOCKER_IMAGE = banzaicloud/cloudinfo
# Build variables
BUILD_DIR ?= build
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
LDFLAGS += -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE}
export CGO_ENABLED ?= 0
ifeq (${VERBOSE}, 1)
ifeq ($(filter -v,${GOARGS}),)
GOARGS += -v
endif
TEST_FORMAT = short-verbose
endif
# Docker variables
DOCKER_TAG ?= ${VERSION}
MISSPELL_VERSION = 0.3.4
GQLGEN_VERSION = 0.8.3
GOTESTSUM_VERSION = 0.4.2
GOLANGCI_VERSION = 1.27.0
LICENSEI_VERSION = 0.2.0
OPENAPI_GENERATOR_VERSION = v4.1.3
GOLANG_VERSION = 1.14
SWAGGER_VERSION = 0.21.0
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./client/*")
SWAGGER_PI_TMP_FILE = ./api/openapi-spec/cloudinfo.json
SWAGGER_PI_FILE = ./api/openapi-spec/cloudinfo.yaml
## include "generic" targets
include main-targets.mk
.PHONY: swagger2openapi
swagger2openapi:
ifeq ($(shell which swagger2openapi),)
npm install -g swagger2openapi
endif
bin/swagger: bin/swagger-${SWAGGER_VERSION}
@ln -sf swagger-${SWAGGER_VERSION} bin/swagger
bin/swagger-${SWAGGER_VERSION}: bin/gobin
@mkdir -p bin
GOBIN=bin/ bin/gobin github.com/go-swagger/go-swagger/cmd/swagger@v${SWAGGER_VERSION}
@mv bin/swagger bin/swagger-${SWAGGER_VERSION}
.PHONY: swagger
swagger: bin/swagger
bin/swagger generate spec -m -o $(SWAGGER_PI_TMP_FILE)
swagger2openapi -y $(SWAGGER_PI_TMP_FILE) > $(SWAGGER_PI_FILE)
define generate_openapi_client
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo rm -rf ${3}; else rm -rf ${3}; fi
docker run --rm -v $${PWD}:/local openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} generate \
--additional-properties packageName=${2} \
--additional-properties withGoCodegenComment=true \
-i /local/${1} \
-g go \
-o /local/${3}
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo chown -R $(shell id -u):$(shell id -g) ${3}; fi
rm ${3}/{.travis.yml,git_push.sh,go.*}
endef
api/openapi-spec/cloudinfo.yaml:swagger
.PHONY: generate-cloudinfo-client
generate-cloudinfo-client: api/openapi-spec/cloudinfo.yaml ## Generate client from Cloudinfo OpenAPI spec
$(call generate_openapi_client,api/openapi-spec/cloudinfo.yaml,cloudinfo,.gen/cloudinfo-client)