forked from redhat-developer/app-services-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
133 lines (107 loc) · 4.22 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
.DEFAULT_GOAL := help
SHELL = bash
# see internal/build.go on build configurations
RHOAS_VERSION ?= "dev"
REPOSITORY_OWNER ?= "redhat-developer"
REPOSITORY_NAME ?= "app-services-cli"
TERMS_REVIEW_EVENT_CODE ?= "onlineService"
TERMS_REVIEW_SITE_CODE ?= "ocm"
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.Version=$(RHOAS_VERSION) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.RepositoryOwner=$(REPOSITORY_OWNER) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.RepositoryName=$(REPOSITORY_NAME) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.TermsReviewEventCode=$(TERMS_REVIEW_EVENT_CODE) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/redhat-developer/app-services-cli/internal/build.TermsReviewSiteCode=$(TERMS_REVIEW_SITE_CODE) $(GO_LDFLAGS)
BUILDFLAGS :=
ifdef DEBUG
BUILDFLAGS := -gcflags "all=-N -l" $(BUILDFLAGS)
endif
# The details of the application:
binary:=rhoas
amsapi_dir=./pkg/api/ams/amsclient
decisapi_dir=./pkg/api/decis/client
# Enable Go modules:
export GO111MODULE=on
# Prints a list of useful targets.
help:
@echo ""
@echo "RHOAS CLI"
@echo ""
@echo "make lint run golangci-lint"
@echo "make binary compile binaries"
@echo "make test run tests"
@echo "make format format files"
@echo "make openapi/pull pull openapi definition"
@echo "make openapi/generate generate openapi modules"
@echo "make openapi/validate validate openapi schema"
@echo "make pkger bundle static assets"
@echo "make docs/check check if docs need to be updated"
@echo "make docs/generate generate the docs"
@echo "$(fake)"
.PHONY: help
# Requires golangci-lint to be installed @ $(go env GOPATH)/bin/golangci-lint
# https://golangci-lint.run/usage/install/
lint:
golangci-lint run cmd/... pkg/... internal/...
.PHONY: lint
generate:
go generate ./...
# Build binaries
# NOTE it may be necessary to use CGO_ENABLED=0 for backwards compatibility with centos7 if not using centos7
binary:
go build $(BUILDFLAGS) -ldflags "${GO_LDFLAGS}" -o ${binary} ./cmd/rhoas
.PHONY: binary
install:
go install -trimpath $(BUILDFLAGS) -ldflags "${GO_LDFLAGS}" ./cmd/rhoas
.PHONY: install
# Runs the integration tests.
test/integration: install
go test ./test/integration
.PHONY: test/integration
# Runs the integration tests.
test/unit: install
go test -count=1 ./pkg/...
.PHONY: test/unit
openapi/validate: openapi/decis/validate
.PHONY: openapi/validate
openapi/generate: openapi/decis/generate openapi/validate
.PHONY: openapi/generate
openapi/ams/generate:
openapi-generator-cli generate -i openapi/ams.json -g go --package-name amsclient -p="generateInterfaces=true" --ignore-file-override=$$(pwd)/.openapi-generator-ignore -o ${amsapi_dir}
# generate mock
moq -out ${amsapi_dir}/default_api_mock.go ${amsapi_dir} DefaultApi
gofmt -w ${amsapi_dir}
.PHONY: openapi/ams/generate
# validate the openapi schema
openapi/decis/validate:
openapi-generator-cli validate -i openapi/decision-service.yaml
.PHONY: openapi/decis/validate
# generate the openapi schema
openapi/decis/generate:
rm -f ${decisapi_dir}/model_*.go
openapi-generator-cli generate -i openapi/decision-service.yaml -g go --package-name decisclient -p="generateInterfaces=true" --ignore-file-override=$$(pwd)/.openapi-generator-ignore -o ${decisapi_dir}
openapi-generator-cli validate -i openapi/decision-service.yaml
# generate mock
moq -out ${decisapi_dir}/default_api_mock.go ${decisapi_dir} DefaultApi
gofmt -w ${decisapi_dir}
.PHONY: openapi/decis/generate
mock-api/start:
echo -e "y" | npx @rhoas/api-mock
.PHONY: mock-api/start
# clean up code and dependencies
format:
@go mod tidy
@gofmt -w `find . -type f -name '*.go'`
.PHONY: format
# Symlink common git hookd into .git directory
githooks:
ln -fs $$(pwd)/githooks/pre-commit .git/hooks
.PHONY: githooks
docs/check: docs/generate
./scripts/check-docs.sh
.PHONY: docs/check
docs/generate:
GENERATE_DOCS=true go run ./cmd/rhoas
.PHONY: docs/generate
docs/generate-modular-docs: docs/generate
SRC_DIR=$$(pwd)/docs/commands DEST_DIR=$$(pwd)/dist go run ./cmd/modular-docs
.PHONY: docs/generate-modular-docs