-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (131 loc) · 5.31 KB
/
Copy pathMakefile
File metadata and controls
159 lines (131 loc) · 5.31 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
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
154
155
156
157
158
159
# Copyright 2026 The Flux Authors
# SPDX-License-Identifier: Apache-2.0
# Makefile for building and testing the flux-schema CLI.
DOCKER_IMAGE ?= ghcr.io/fluxcd/flux-schema:latest-dev
VERSION_DEV ?=0.0.0-$(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --short HEAD)-$(shell date +%s)
GO_TEST_ARGS ?=
GO_RUN_ARGS ?=
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
# Get the currently used golang install path
# (in GOPATH/bin, unless GOBIN is set).
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
.PHONY: all
all: test build ## Run test and build targets.
##@ Development
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: tidy
tidy: ## Run go mod tidy.
go mod tidy
.PHONY: test
test: tidy fmt generate vet ## Run all unit tests.
go test ./... $(GO_TEST_ARGS) -coverprofile cover.out
.PHONY: lint
lint: golangci-lint ## Run golangci linters.
$(GOLANGCI_LINT) run
.PHONY: build
build: tidy fmt generate vet ## Build CLI binary.
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(VERSION_DEV)" -o ./bin/flux-schema ./cmd/flux-schema/
.PHONY: docker-build
docker-build: ## Build docker image with the CLI.
docker build -t $(DOCKER_IMAGE) --build-arg VERSION=$(VERSION_DEV) -f Dockerfile .
.PHONY: install
install: test lint build ## Test, lint, build and copy the binary to GOBIN.
cp bin/flux-schema $(GOBIN)
.PHONY: run
run: build ## Run CLI binary.
./bin/flux-schema $(GO_RUN_ARGS)
.PHONY: generate
generate: generate-json-schemas ## Generate deep copy and JSON Schema artifacts
.PHONY: generate-api
generate-api: controller-gen ## Generate API artifacts
$(CONTROLLER_GEN) object:headerFile="api/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) schemapatch:manifests="./" paths="./..."
.PHONY: generate-json-schemas
generate-json-schemas: generate-api ## Generate JSON Schemas
mkdir -p ./catalog/latest/schema.plugin.fluxcd.io ./docs
go run ./tools/schema-gen \
-controller-gen "$(CONTROLLER_GEN)" \
-group "schema.plugin.fluxcd.io" \
-version "v1beta1" \
-kind "Report" \
-type "github.com/fluxcd/flux-schema/api/v1beta1.ReportSpec" \
-field "report" \
-schema-field \
-id "https://raw.githubusercontent.com/fluxcd/flux-schema/main/docs/report-v1beta1.json" \
-out ./docs/report-v1beta1.json
cp ./docs/report-v1beta1.json ./catalog/latest/schema.plugin.fluxcd.io/report_v1beta1.json
go run ./tools/schema-gen \
-controller-gen "$(CONTROLLER_GEN)" \
-group "schema.plugin.fluxcd.io" \
-version "v1beta1" \
-kind "Config" \
-type "github.com/fluxcd/flux-schema/api/v1beta1.Config" \
-direct \
-id "https://raw.githubusercontent.com/fluxcd/flux-schema/main/docs/config-v1beta1.json" \
-out ./docs/config-v1beta1.json
cp ./docs/config-v1beta1.json ./catalog/latest/schema.plugin.fluxcd.io/config_v1beta1.json
go run ./tools/schema-gen \
-controller-gen "$(CONTROLLER_GEN)" \
-group "schema.plugin.fluxcd.io" \
-version "v1beta1" \
-kind "Inventory" \
-type "github.com/fluxcd/flux-schema/api/v1beta1.InventorySpec" \
-field "inventory" \
-schema-field \
-id "https://raw.githubusercontent.com/fluxcd/flux-schema/main/docs/inventory-v1beta1.json" \
-out ./docs/inventory-v1beta1.json
cp ./docs/inventory-v1beta1.json ./catalog/latest/schema.plugin.fluxcd.io/inventory_v1beta1.json
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
GOVULNCHECK ?= $(LOCALBIN)/govulncheck
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.21.0
GOLANGCI_LINT_VERSION ?= v2.11.4
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
.PHONY: govulncheck
govulncheck: $(GOVULNCHECK) ## Run govulncheck.
$(GOVULNCHECK): $(LOCALBIN)
$(call go-install-tool,$(GOVULNCHECK),golang.org/x/vuln/cmd/govulncheck,latest)
@$(GOVULNCHECK) ./...
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
##@ General
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)