-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (48 loc) · 2.07 KB
/
Makefile
File metadata and controls
66 lines (48 loc) · 2.07 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
# Makefile for generating REST clients + Cobra commands from all OpenAPI specs
API_DIR := api
SERVICES := $(shell find $(API_DIR) -mindepth 2 -maxdepth 2 -type f -name "openapi.yaml" | \
sed -E "s|$(API_DIR)/([^/]+)/openapi.yaml|\1|")
GOCMD := go
GEN := ./tools/cobra-gen
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
ifndef GOBIN # derive value from gopath (default to first entry, similar to 'go get')
GOBIN := $(shell go env GOPATH | sed 's/:.*//')/bin
endif
.PHONY: generate build clean
# Generate code for every service folder that owns an openapi.yaml
generate: $(GOBIN)/oapi-codegen $(SERVICES:%=generate-%)
tools = $(addprefix $(GOBIN)/, golangci-lint goimports govulncheck protoc-gen-go protoc-gen-go-grpc gci oapi-codegen)
tools: $(tools) ## Install tools required for the build
@echo "Installed tools"
generate-%:
@echo ">> Generating $*"
$(GOCMD) run $(GEN) --service=$* --in=$(API_DIR)/$*/openapi.yaml --out=cmd/$* --cmd=$(API_DIR)/$*/command.yaml
build-all: generate format
CGO_ENABLED=0 $(GOCMD) build -ldflags="-s -w" -o hc ./cmd/hc
build: generate format
CGO_ENABLED=0 $(GOCMD) build -ldflags="-s -w" -o hc ./cmd/hc
# Remove generated artifacts
clean:
rm -rf internal/api/*
rm -f cmd/*/*_gen.go
format: tools # Format go code and error if any changes are made
@echo "Formatting ..."
@goimports -w .
@gci write --skip-generated --custom-order -s standard -s "prefix(github.com/harness/)" -s default -s blank -s dot .
@echo "Formatting complete"
# Install oapi-codegen
$(GOBIN)/oapi-codegen:
@echo "🔘 Installing oapi-codegen... (`date '+%H:%M:%S'`)"
@go install github.com/oapi-codegen/oapi-codegen/v2/cmd/[email protected]
# Generate mock binary fixtures (NuGet .nupkg, NPM .tgz, Dart .tar.gz)
# into testdata/binary/ for the mock_jfrog adapter. Run once after cloning.
mock-init:
$(GOCMD) run ./module/ar/migrate/adapter/mock_jfrog/cmd
# Remove generated mock binary fixtures
mock-clean:
rm -rf module/ar/migrate/adapter/mock_jfrog/testdata/binary
# For test coverage
test:
go test -timeout 30m -cover -coverprofile=coverage.out ./...