forked from operator-framework/operator-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
182 lines (151 loc) · 6.95 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
SHELL = /bin/bash
GO := go
CMDS := $(addprefix bin/, $(shell ls ./cmd | grep -v opm))
OPM := $(addprefix bin/, opm)
SPECIFIC_UNIT_TEST := $(if $(TEST),-run $(TEST),)
SPECIFIC_SKIP_UNIT_TEST := $(if $(SKIP),-skip $(SKIP),)
extra_env := $(GOENV)
export PKG := github.com/operator-framework/operator-registry
export GIT_COMMIT := $(or $(SOURCE_GIT_COMMIT),$(shell git rev-parse --short HEAD))
export OPM_VERSION := $(or $(SOURCE_GIT_TAG),$(shell git describe --always --tags HEAD))
export BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
.DEFAULT_GOAL := all
# bingo manages consistent tooling versions for things like kind, kustomize, etc.
include .bingo/Variables.mk
# protoc is not a go binary, so we need a custom recipe for it.
PROTOC := ./tools/bin/protoc
PROTOC_VERSION := 27.0
.PHONY: $(PROTOC)
$(PROTOC):
./scripts/ensure-protoc.sh $(PROTOC_VERSION)
# define characters
null :=
space := $(null) #
comma := ,
# default to json1 for sqlite3
TAGS := -tags=json1
# Cluster to use for e2e testing
CLUSTER ?= ""
ifeq ($(CLUSTER), kind)
# add kind to the list of tags
TAGS += kind
# convert tag format from space to comma list
TAGS := $(subst $(space),$(comma),$(strip $(TAGS)))
endif
# -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
ifeq ($(shell go env GOARCH),s390x)
TEST_RACE :=
else
TEST_RACE := -race
endif
.PHONY: all
all: clean test build
$(CMDS):
$(extra_env) $(GO) build $(extra_flags) $(TAGS) -o $@ ./cmd/$(notdir $@)
.PHONY: $(OPM)
$(OPM): opm_version_flags=-ldflags "-X '$(PKG)/cmd/opm/version.gitCommit=$(GIT_COMMIT)' -X '$(PKG)/cmd/opm/version.opmVersion=$(OPM_VERSION)' -X '$(PKG)/cmd/opm/version.buildDate=$(BUILD_DATE)'"
$(OPM):
$(extra_env) $(GO) build $(opm_version_flags) $(extra_flags) $(TAGS) -o $@ ./cmd/$(notdir $@)
.PHONY: build
build: clean $(CMDS) $(OPM)
.PHONY: cross
cross: opm_version_flags=-ldflags "-X '$(PKG)/cmd/opm/version.gitCommit=$(GIT_COMMIT)' -X '$(PKG)/cmd/opm/version.opmVersion=$(OPM_VERSION)' -X '$(PKG)/cmd/opm/version.buildDate=$(BUILD_DATE)'"
cross:
ifeq ($(shell go env GOARCH),amd64)
GOOS=darwin CC=o64-clang CXX=o64-clang++ CGO_ENABLED=1 $(GO) build $(opm_version_flags) $(TAGS) -o "bin/darwin-amd64-opm" --ldflags "-extld=o64-clang" ./cmd/opm
GOOS=windows CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_ENABLED=1 $(GO) build $(opm_version_flags) $(TAGS) -o "bin/windows-amd64-opm" --ldflags "-extld=x86_64-w64-mingw32-gcc" -buildmode=exe ./cmd/opm
endif
.PHONY: static
static: extra_flags=-ldflags '-w -extldflags "-static"' -tags "json1"
static: build
.PHONY: unit
unit:
$(GO) test -coverprofile=coverage.out $(SPECIFIC_UNIT_TEST) $(SPECIFIC_SKIP_UNIT_TEST) $(TAGS) $(TEST_RACE) -count=1 ./pkg/... ./alpha/...
.PHONY: tidy
tidy:
go mod tidy
go mod verify
.PHONY: verify
verify: tidy codegen lint
git diff --exit-code
.PHONY: sanity-check
sanity-check:
# Build a container with the most recent binaries for this project.
# Does not include the database, which needs to be added separately.
docker build -f upstream-builder.Dockerfile -t sanity-container .
# TODO: add more invocations of the opm binary here
# serve the container for a second, using the bundles.db in testdata
docker run --rm -it -v "$(shell pwd)"/pkg/lib/indexer/testdata/:/database sanity-container \
./bin/opm registry serve --database /database/bundles.db --timeout-seconds 1
.PHONY: image-upstream
image-upstream:
docker build -f upstream-example.Dockerfile .
.PHONY: lint
lint:
find . -type f -name '*.go' ! -name '*.pb.go' -print0 | xargs -0 goimports -w
.PHONY: bingo-upgrade
bingo-upgrade: $(BINGO) #EXHELP Upgrade tools
@for pkg in $$($(BINGO) list | awk '{ print $$1 }' | tail -n +3); do \
echo "Upgrading $$pkg to latest..."; \
$(BINGO) get "$$pkg@latest"; \
done
.PHONY: codegen
codegen: $(PROTOC) $(PROTOC_GEN_GO_GRPC)
$(PROTOC) --plugin=protoc-gen-go=$(PROTOC_GEN_GO_GRPC) -I pkg/api/ --go_out=pkg/api pkg/api/*.proto
$(PROTOC) --plugin=protoc-gen-go-grpc=$(PROTOC_GEN_GO_GRPC) -I pkg/api/ --go-grpc_out=pkg/api pkg/api/*.proto
.PHONY: generate-fakes
generate-fakes:
$(GO) generate ./...
.PHONY: clean
clean:
@rm -rf ./bin
.PHONY: e2e
e2e: $(GINKGO)
$(GINKGO) --v --randomize-all --progress --trace --randomize-suites --race $(if $(TEST),-focus '$(TEST)') $(TAGS) ./test/e2e -- $(if $(SKIPTLS),-skip-tls-verify true) $(if $(USEHTTP),-use-http true)
.PHONY: release
export OPM_IMAGE_REPO ?= quay.io/operator-framework/opm
export IMAGE_TAG ?= $(OPM_VERSION)
export MAJ_MIN_IMAGE_OR_EMPTY := $(call tagged-or-empty,$(shell echo $(OPM_VERSION) | grep -Eo 'v[0-9]+\.[0-9]+'))
export MAJ_IMAGE_OR_EMPTY := $(call tagged-or-empty,$(shell echo $(OPM_VERSION) | grep -Eo 'v[0-9]+'))
# LATEST_TAG is the latest semver tag in HEAD. Used to deduce whether
# OPM_VERSION is the new latest tag, or a prior minor/patch tag, below.
# NOTE: this can only be relied upon if full git history is present.
# An actions/checkout step must use "fetch-depth: 0", for example.
LATEST_TAG := $(shell git tag -l | tr - \~ | sort -V | tr \~ - | tail -n1)
# LATEST_IMAGE_OR_EMPTY is set to OPM_IMAGE_REPO:latest when OPM_VERSION
# is not a prerelase tag and == LATEST_TAG, otherwise the empty string.
# An empty string causes goreleaser to skip building the manifest image for latest,
# which we do not want when cutting a non-latest release (old minor/patch tag).
export LATEST_IMAGE_OR_EMPTY := $(shell \
echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
&& [ "$(shell echo -e "$(OPM_VERSION)\n$(LATEST_TAG)" | sort -rV | head -n1)" == "$(OPM_VERSION)" ] \
&& echo "$(OPM_IMAGE_REPO):latest" || echo "")
RELEASE_GOOS := $(shell go env GOOS)
RELEASE_ARGS ?= release --clean --snapshot -f release/goreleaser.$(RELEASE_GOOS).yaml
# Note: bingo does not yet support windows (https://github.com/bwplotka/bingo/issues/26)
# so GOOS=windows gets its own way to install goreleaser
ifeq ($(RELEASE_GOOS), windows)
GORELEASER := $(shell pwd)/bin/goreleaser
release: windows-goreleaser-install
else
release: $(GORELEASER)
endif
release:
$(GORELEASER) $(RELEASE_ARGS)
.PHONY: windows-goreleaser-install
windows-goreleaser-install:
# manually install goreleaser from the bingo directory in the same way bingo (currently) installs it.
# This is done to ensure the same version of goreleaser is used across all platforms
mkdir -p $(dir $(GORELEASER))
@echo "(re)installing $(GORELEASER)"
GOWORK=off $(GO) build -mod=mod -modfile=.bingo/goreleaser.mod -o=$(GORELEASER) "github.com/goreleaser/goreleaser"
# tagged-or-empty returns $(OPM_IMAGE_REPO):$(1) when HEAD is assigned a non-prerelease semver tag,
# otherwise the empty string. An empty string causes goreleaser to skip building
# the manifest image for a trunk commit when it is not a release commit.
# In other words, this function will return "" if the tag is not in vX.Y.Z format.
define tagged-or-empty
$(shell \
echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
&& git describe --tags --exact-match HEAD >/dev/null 2>&1 \
&& echo "$(OPM_IMAGE_REPO):$(1)" || echo "" )
endef