github.com/wdesplas/cloud-service-broker@v0.0.0-20211027135251-516a8547ca4c/Makefile (about)

     1  SHELL = /bin/bash
     2  GO-VERSION = 1.17
     3  GO-VER = go$(GO-VERSION)
     4  
     5  OSFAMILY=$(shell uname)
     6  ifeq ($(OSFAMILY),Darwin)
     7  OSFAMILY=darwin
     8  else
     9  OSFAMILY=linux
    10  endif
    11  
    12  ifeq ($(USE_GO_CONTAINERS),)
    13  GO=go
    14  GOFMT=gofmt
    15  else
    16  UID:=$(shell id -u)
    17  DOCKER_OPTS=--rm -u $(UID) -v $(HOME):$(HOME) -e HOME -e USER=$(USER) -e USERNAME=$(USER) -w $(PWD)
    18  GO=docker run $(DOCKER_OPTS) -e GOARCH -e GOOS -e CGO_ENABLED golang:$(GO-VERSION) go
    19  GOFMT=docker run $(DOCKER_OPTS) -e GOARCH -e GOOS -e CGO_ENABLED golang:$(GO-VERSION) gofmt
    20  endif
    21  
    22  SRC = $(shell find . -name "*.go" | grep -v "_test\." )
    23  
    24  VERSION := $(or $(VERSION), dev)
    25  
    26  LDFLAGS="-X github.com/wdesplas/cloud-service-broker/utils.Version=$(VERSION)"
    27  
    28  PKG="github.com/wdesplas/cloud-service-broker"
    29  
    30  .PHONY: deps-go-binary
    31  deps-go-binary:
    32  ifeq ($(SKIP_GO_VERSION_CHECK),)
    33  	echo "Expect: $(GO-VER)" && \
    34  		echo "Actual: $$($(GO) version)" && \
    35  	 	$(GO) version | grep $(GO-VER) > /dev/null
    36  endif
    37  
    38  ###### Help ###################################################################
    39  
    40  .DEFAULT_GOAL = help
    41  
    42  .PHONY: help
    43  
    44  help: ## list Makefile targets
    45  	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
    46  
    47  ###### Test ###################################################################
    48  
    49  .PHONY: test
    50  test: download lint test-units test-integration ## run lint and unit tests
    51  
    52  .PHONY: test-units
    53  test-units: deps-go-binary ## run unit tests
    54  	$(GO) test $(PKG)/brokerapi/... $(PKG)/cmd/... $(PKG)/db_service/... $(PKG)/internal/... $(PKG)/pkg/... $(PKG)/utils/... -tags=service_broker
    55  
    56  .PHONY: test-integration
    57  test-integration: deps-go-binary ## run integration tests
    58  	$(GO) run github.com/onsi/ginkgo/ginkgo -p integrationtest/...
    59  
    60  ###### Build ##################################################################
    61  
    62  ./build/cloud-service-broker.linux: $(SRC)
    63  	CGO_ENABLED=0 GOARCH=amd64 GOOS=linux $(GO) build -o ./build/cloud-service-broker.linux -ldflags ${LDFLAGS}
    64  
    65  ./build/cloud-service-broker.darwin: $(SRC)
    66  	GOARCH=amd64 GOOS=darwin $(GO) build -o ./build/cloud-service-broker.darwin -ldflags ${LDFLAGS}
    67  
    68  .PHONY: build
    69  build: deps-go-binary ./build/cloud-service-broker.linux ./build/cloud-service-broker.darwin ## build binary
    70  
    71  .PHONY: generate
    72  generate: ## generate test fakes
    73  	${GO} generate ./...
    74  	make format
    75  
    76  .PHONY: download
    77  download: ## download go module dependencies
    78  	${GO} mod download
    79  
    80  ###### Package ################################################################
    81  
    82  .PHONY: package
    83  package: ./build/cloud-service-broker.$(OSFAMILY) ./tile.yml ./manifest.yml docs/customization.md ## package binary
    84  
    85  ./tile.yml:
    86  	./build/cloud-service-broker.$(OSFAMILY) generate tile > ./tile.yml
    87  
    88  ./manifest.yml:
    89  	./build/cloud-service-broker.$(OSFAMILY) generate manifest > ./manifest.yml
    90  
    91  docs/customization.md:
    92  	./build/cloud-service-broker.$(OSFAMILY) generate customization > docs/customization.md
    93  
    94  ###### Clean ##################################################################
    95  
    96  .PHONY: clean
    97  clean: deps-go-binary ## clean up from previous builds
    98  	-$(GO) clean --modcache
    99  	-rm -rf ./build
   100  
   101  ###### Lint ###################################################################
   102  
   103  .PHONY: lint
   104  lint: checkformat checkimports vet staticcheck ## lint the source
   105  
   106  checkformat: ## Checks that the code is formatted correctly
   107  	@@if [ -n "$$(${GOFMT} -s -e -l -d .)" ]; then       \
   108  		echo "gofmt check failed: run 'make format'"; \
   109  		exit 1;                                       \
   110  	fi
   111  
   112  checkimports: ## Checks that imports are formatted correctly
   113  	@@if [ -n "$$(${GO} run golang.org/x/tools/cmd/goimports -l -d .)" ]; then \
   114  		echo "goimports check failed: run 'make format'";                      \
   115  		exit 1;                                                                \
   116  	fi
   117  
   118  vet: ## Runs go vet
   119  	${GO} vet ./...
   120  
   121  staticcheck: ## Runs staticcheck
   122  	${GO} run honnef.co/go/tools/cmd/staticcheck ./...
   123  
   124  ###### Format #################################################################
   125  
   126  .PHONY: format
   127  format: ## format the source
   128  	${GOFMT} -s -e -l -w .
   129  	${GO} run golang.org/x/tools/cmd/goimports -l -w .
   130  
   131  ###### Image ##################################################################
   132  
   133  .PHONY: build-image
   134  build-image: Dockerfile ## build a Docker image
   135  	docker build --tag csb .
   136  
   137  ###### Env Var Checks #########################################################
   138  
   139  .PHONY: security-user-name
   140  security-user-name:
   141  ifndef SECURITY_USER_NAME
   142  	$(error variable SECURITY_USER_NAME not defined)
   143  endif
   144  
   145  .PHONY: security-user-password
   146  security-user-password:
   147  ifndef SECURITY_USER_PASSWORD
   148  	$(error variable SECURITY_USER_PASSWORD not defined)
   149  endif
   150  
   151  .PHONY: db-host
   152  db-host:
   153  ifndef DB_HOST
   154  	$(error variable DB_HOST not defined)
   155  endif
   156  
   157  .PHONY: db-username
   158  db-username:
   159  ifndef DB_USERNAME
   160  	$(error variable DB_USERNAME not defined)
   161  endif
   162  
   163  .PHONY: db-password
   164  db-password:
   165  ifndef DB_PASSWORD
   166  	$(error variable DB_PASSWORD not defined)
   167  endif
   168  
   169  ###### End ####################################################################