github.com/dean7474/operator-registry@v1.21.1-0.20220418203638-d4717f98c2e5/Makefile (about)

     1  SHELL = /bin/bash
     2  GO := GOFLAGS="-mod=vendor" go
     3  CMDS := $(addprefix bin/, $(shell ls ./cmd | grep -v opm))
     4  OPM := $(addprefix bin/, opm)
     5  SPECIFIC_UNIT_TEST := $(if $(TEST),-run $(TEST),)
     6  extra_env := $(GOENV)
     7  export PKG := github.com/operator-framework/operator-registry
     8  export GIT_COMMIT := $(or $(SOURCE_GIT_COMMIT),$(shell git rev-parse --short HEAD))
     9  export OPM_VERSION := $(or $(SOURCE_GIT_TAG),$(shell git describe --always --tags HEAD))
    10  export BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
    11  
    12  # define characters
    13  null  :=
    14  space := $(null) #
    15  comma := ,
    16  # default to json1 for sqlite3
    17  TAGS := -tags=json1
    18  
    19  # Cluster to use for e2e testing
    20  CLUSTER ?= ""
    21  ifeq ($(CLUSTER), kind)
    22  # add kind to the list of tags
    23  TAGS += kind
    24  # convert tag format from space to comma list
    25  TAGS := $(subst $(space),$(comma),$(strip $(TAGS)))
    26  endif
    27  
    28  # -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
    29  ifeq ($(shell go env GOARCH),s390x)
    30  TEST_RACE :=
    31  else
    32  TEST_RACE := -race
    33  endif
    34  
    35  .PHONY: all
    36  all: clean test build
    37  
    38  $(CMDS):
    39  	$(extra_env) $(GO) build $(extra_flags) $(TAGS) -o $@ ./cmd/$(notdir $@)
    40  
    41  .PHONY: $(OPM)
    42  $(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)'"
    43  $(OPM):
    44  	$(extra_env) $(GO) build $(opm_version_flags) $(extra_flags) $(TAGS) -o $@ ./cmd/$(notdir $@)
    45  
    46  .PHONY: build
    47  build: clean $(CMDS) $(OPM)
    48  
    49  .PHONY: cross
    50  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)'"
    51  cross:
    52  ifeq ($(shell go env GOARCH),amd64)
    53  	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
    54  	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
    55  endif
    56  
    57  .PHONY: static
    58  static: extra_flags=-ldflags '-w -extldflags "-static"' -tags "json1"
    59  static: build
    60  
    61  .PHONY: unit
    62  unit:
    63  	$(GO) test -coverprofile=coverage.out $(SPECIFIC_UNIT_TEST) $(TAGS) $(TEST_RACE) -count=1 ./pkg/... ./alpha/...
    64  
    65  .PHONY: sanity-check
    66  sanity-check:
    67  	# Build a container with the most recent binaries for this project.
    68  	# Does not include the database, which needs to be added separately.
    69  	docker build -f upstream-builder.Dockerfile -t sanity-container .
    70  
    71  	# TODO: add more invocations of the opm binary here
    72  
    73  	# serve the container for a second, using the bundles.db in testdata
    74  	docker run --rm -it -v "$(shell pwd)"/pkg/lib/indexer/testdata/:/database sanity-container \
    75  		./bin/opm registry serve --database /database/bundles.db --timeout-seconds 1
    76  
    77  .PHONY: image
    78  image:
    79  	docker build .
    80  
    81  .PHONY: image-upstream
    82  image-upstream:
    83  	docker build -f upstream-example.Dockerfile .
    84  
    85  .PHONY: vendor
    86  vendor:
    87  	$(GO) mod tidy
    88  	$(GO) mod vendor
    89  	$(GO) mod verify
    90  
    91  .PHONY: lint
    92  lint:
    93  	find . -name '*.go' -not -path "./vendor/*" | xargs goimports -w
    94  
    95  .PHONY: codegen
    96  codegen:
    97  	protoc -I pkg/api/ --go_out=pkg/api pkg/api/*.proto
    98  	protoc -I pkg/api/ --go-grpc_out=pkg/api pkg/api/*.proto
    99  	protoc -I pkg/api/grpc_health_v1 --go_out=pkg/api/grpc_health_v1 pkg/api/grpc_health_v1/*.proto
   100  	protoc -I pkg/api/grpc_health_v1 --go-grpc_out=pkg/api/grpc_health_v1 pkg/api/grpc_health_v1/*.proto
   101  
   102  .PHONY: container-codegen
   103  container-codegen:
   104  	docker build -t operator-registry:codegen -f codegen.Dockerfile .
   105  	docker run --name temp-codegen operator-registry:codegen /bin/true
   106  	docker cp temp-codegen:/codegen/pkg/api/. ./pkg/api
   107  	docker rm temp-codegen
   108  
   109  .PHONY: generate-fakes
   110  generate-fakes:
   111  	$(GO) generate ./...
   112  
   113  .PHONY: clean
   114  clean:
   115  	@rm -rf ./bin
   116  
   117  .PHONY: e2e
   118  e2e:
   119  	$(GO) run github.com/onsi/ginkgo/ginkgo --v --randomizeAllSpecs --randomizeSuites --race $(if $(TEST),-focus '$(TEST)') $(TAGS) ./test/e2e -- $(if $(SKIPTLS),-skip-tls-verify true) $(if $(USEHTTP),-use-http true)
   120  
   121  
   122  .PHONY: release
   123  export OPM_IMAGE_REPO ?= quay.io/operator-framework/opm
   124  export IMAGE_TAG ?= $(OPM_VERSION)
   125  export MAJ_MIN_IMAGE_OR_EMPTY ?= $(call tagged-or-empty,$(shell echo $(OPM_VERSION) | grep -Eo 'v[0-9]+\.[0-9]+'))
   126  export MAJ_IMAGE_OR_EMPTY ?= $(call tagged-or-empty,$(shell echo $(OPM_VERSION) | grep -Eo 'v[0-9]+'))
   127  # LATEST_TAG is the latest semver tag in HEAD. Used to deduce whether
   128  # OPM_VERSION is the new latest tag, or a prior minor/patch tag, below.
   129  # NOTE: this can only be relied upon if full git history is present.
   130  # An actions/checkout step must use "fetch-depth: 0", for example.
   131  LATEST_TAG := $(shell git tag -l | tr - \~ | sort -V | tr \~ - | tail -n1)
   132  # LATEST_IMAGE_OR_EMPTY is set to OPM_IMAGE_REPO:latest when OPM_VERSION
   133  # is not a prerelase tag and == LATEST_TAG, otherwise the empty string.
   134  # An empty string causes goreleaser to skip building the manifest image for latest,
   135  # which we do not want when cutting a non-latest release (old minor/patch tag).
   136  export LATEST_IMAGE_OR_EMPTY ?= $(shell \
   137  	echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
   138  	&& [ "$(shell echo -e "$(OPM_VERSION)\n$(LATEST_TAG)" | sort -rV | head -n1)" == "$(OPM_VERSION)" ] \
   139  	&& echo "$(OPM_IMAGE_REPO):latest" || echo "")
   140  release: RELEASE_ARGS ?= release --rm-dist --snapshot -f release/goreleaser.$(shell go env GOOS).yaml
   141  release:
   142  	./scripts/fetch goreleaser 1.4.1 && ./bin/goreleaser $(RELEASE_ARGS)
   143  
   144  # tagged-or-empty returns $(OPM_IMAGE_REPO):$(1) when HEAD is assigned a non-prerelease semver tag,
   145  # otherwise the empty string. An empty string causes goreleaser to skip building
   146  # the manifest image for a trunk commit when it is not a release commit.
   147  # In other words, this function will return "" if the tag is not in vX.Y.Z format.
   148  define tagged-or-empty
   149  $(shell \
   150  	echo $(OPM_VERSION) | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$$' \
   151  	&& git describe --tags --exact-match HEAD >/dev/null 2>&1 \
   152  	&& echo "$(OPM_IMAGE_REPO):$(1)" || echo "" )
   153  endef