github.com/ethersphere/bee/v2@v2.2.0/Makefile (about)

     1  GO ?= go
     2  GOBIN ?= $$($(GO) env GOPATH)/bin
     3  GOLANGCI_LINT ?= $(GOBIN)/golangci-lint
     4  GOLANGCI_LINT_VERSION ?= v1.55.0
     5  GOGOPROTOBUF ?= protoc-gen-gogofaster
     6  GOGOPROTOBUF_VERSION ?= v1.3.1
     7  BEEKEEPER_INSTALL_DIR ?= $(GOBIN)
     8  BEEKEEPER_USE_SUDO ?= false
     9  BEEKEEPER_CLUSTER ?= local
    10  BEELOCAL_BRANCH ?= main
    11  BEEKEEPER_BRANCH ?= master
    12  REACHABILITY_OVERRIDE_PUBLIC ?= false
    13  BATCHFACTOR_OVERRIDE_PUBLIC ?= 5
    14  
    15  BEE_API_VERSION ?= "$(shell grep '^  version:' openapi/Swarm.yaml | awk '{print $$2}')"
    16  
    17  VERSION ?= "$(shell git describe --tags --abbrev=0 | cut -c2-)"
    18  COMMIT_HASH ?= "$(shell git describe --long --dirty --always --match "" || true)"
    19  CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)"
    20  COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)"
    21  LDFLAGS ?= -s -w \
    22  -X github.com/ethersphere/bee/v2.version="$(VERSION)" \
    23  -X github.com/ethersphere/bee/v2.commitHash="$(COMMIT_HASH)" \
    24  -X github.com/ethersphere/bee/v2.commitTime="$(COMMIT_TIME)" \
    25  -X github.com/ethersphere/bee/v2/pkg/api.Version="$(BEE_API_VERSION)" \
    26  -X github.com/ethersphere/bee/v2/pkg/p2p/libp2p.reachabilityOverridePublic="$(REACHABILITY_OVERRIDE_PUBLIC)" \
    27  -X github.com/ethersphere/bee/v2/pkg/postage/listener.batchFactorOverridePublic="$(BATCHFACTOR_OVERRIDE_PUBLIC)"
    28  
    29  .PHONY: all
    30  all: build lint test-race binary
    31  
    32  .PHONY: binary
    33  binary: export CGO_ENABLED=0
    34  binary: dist FORCE
    35  	$(GO) version
    36  	$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o dist/bee ./cmd/bee
    37  
    38  dist:
    39  	mkdir $@
    40  
    41  .PHONY: beekeeper
    42  beekeeper:
    43  ifeq ($(BEEKEEPER_BRANCH), master)
    44  	curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/master/scripts/install.sh | BEEKEEPER_INSTALL_DIR=$(BEEKEEPER_INSTALL_DIR) USE_SUDO=$(BEEKEEPER_USE_SUDO) bash
    45  else
    46  	git clone -b $(BEEKEEPER_BRANCH) https://github.com/ethersphere/beekeeper.git && mv beekeeper beekeeper_src && cd beekeeper_src && mkdir -p $(BEEKEEPER_INSTALL_DIR) && make binary
    47  ifeq ($(BEEKEEPER_USE_SUDO), true)
    48  	sudo mv beekeeper_src/dist/beekeeper $(BEEKEEPER_INSTALL_DIR)
    49  else
    50  	mv beekeeper_src/dist/beekeeper $(BEEKEEPER_INSTALL_DIR)
    51  endif
    52  	rm -rf beekeeper_src
    53  endif
    54  	test -f ~/.beekeeper.yaml || curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/$(BEEKEEPER_BRANCH)/config/beekeeper-local.yaml -o ~/.beekeeper.yaml
    55  	mkdir -p ~/.beekeeper && curl -sSfL https://raw.githubusercontent.com/ethersphere/beekeeper/$(BEEKEEPER_BRANCH)/config/local.yaml -o ~/.beekeeper/local.yaml
    56  
    57  .PHONY: beelocal
    58  beelocal:
    59  	curl -sSfL https://raw.githubusercontent.com/ethersphere/beelocal/$(BEELOCAL_BRANCH)/beelocal.sh | bash
    60  
    61  .PHONY: deploylocal
    62  deploylocal:
    63  	beekeeper create bee-cluster --cluster-name $(BEEKEEPER_CLUSTER)
    64  
    65  .PHONY: testlocal
    66  testlocal:
    67  	export PATH=${PATH}:$(GOBIN)
    68  	beekeeper check --cluster-name local --checks=ci-full-connectivity,ci-manifest,ci-pingpong,ci-pss,ci-pushsync-chunks,ci-retrieval,ci-settlements,ci-soc
    69  
    70  .PHONY: testlocal-all
    71  testlocal-all: beekeeper beelocal deploylocal testlocal
    72  
    73  .PHONY: install-formatters
    74  install-formatters:
    75  	$(GO) get github.com/daixiang0/gci
    76  	$(GO) install mvdan.cc/gofumpt@latest
    77  
    78  FOLDER=$(shell pwd)
    79  
    80  .PHONY: format
    81  format:
    82  	$(GOBIN)/gofumpt -l -w $(FOLDER)
    83  	$(GOBIN)/gci -w -local $(go list -m) `find $(FOLDER) -type f \! -name "*.pb.go" -name "*.go" \! -path \*/\.git/\* -exec echo {} \;`
    84  
    85  .PHONY: lint
    86  lint: linter
    87  	$(GOLANGCI_LINT) run ./...
    88  
    89  .PHONY: linter
    90  linter:
    91  	test -f $(GOLANGCI_LINT) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$($(GO) env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
    92  
    93  .PHONY: check-whitespace
    94  check-whitespace:
    95  	TREE=$$(git hash-object -t tree /dev/null); \
    96  	TW=$$(git diff-index --cached --check --diff-filter=d "$${TREE}"); \
    97  	[ "$${TW}" != "" ] && echo "Trailing whitespaces found:\n $${TW}" && exit 1; exit 0
    98  
    99  .PHONY: test-race
   100  test-race:
   101  ifdef cover
   102  	$(GO) test -race -failfast -coverprofile=cover.out -v ./...
   103  else
   104  	$(GO) test -race -failfast -v ./...
   105  endif
   106  
   107  .PHONY: test-integration
   108  test-integration:
   109  	$(GO) test -tags=integration -v ./...
   110  
   111  .PHONY: test
   112  test:
   113  ifdef cover
   114  	$(GO) test -failfast -coverprofile=cover.out -v ./...
   115  else
   116  	$(GO) test -failfast -v ./...
   117  endif
   118  
   119  .PHONY: test-ci
   120  test-ci:
   121  ifdef cover
   122  	$(GO) test -run "[^FLAKY]$$" -coverprofile=cover.out ./...
   123  else
   124  	$(GO) test -run "[^FLAKY]$$" ./...
   125  endif
   126  
   127  .PHONY: test-ci-race
   128  test-ci-race:
   129  ifdef cover
   130  	$(GO) test -race -run "[^FLAKY]$$" -coverprofile=cover.out ./...
   131  else
   132  	$(GO) test -race -run "[^FLAKY]$$" ./...
   133  endif
   134  
   135  .PHONY: test-ci-flaky
   136  test-ci-flaky:
   137  	$(GO) test -race -run "FLAKY$$" ./...
   138  
   139  .PHONY: build
   140  build: export CGO_ENABLED=0
   141  build:
   142  	$(GO) build -trimpath -ldflags "$(LDFLAGS)" ./...
   143  
   144  .PHONY: githooks
   145  githooks:
   146  	ln -f -s ../../.githooks/pre-push.bash .git/hooks/pre-push
   147  
   148  .PHONY: protobuftools
   149  protobuftools:
   150  	which protoc || ( echo "install protoc for your system from https://github.com/protocolbuffers/protobuf/releases" && exit 1)
   151  	which $(GOGOPROTOBUF) || ( cd /tmp && GO111MODULE=on $(GO) install github.com/gogo/protobuf/$(GOGOPROTOBUF)@$(GOGOPROTOBUF_VERSION) )
   152  
   153  .PHONY: protobuf
   154  protobuf: GOFLAGS=-mod=mod # use modules for protobuf file include option
   155  protobuf: protobuftools
   156  	$(GO) generate -run protoc ./...
   157  
   158  .PHONY: clean
   159  clean:
   160  	$(GO) clean
   161  	rm -rf dist/
   162  
   163  FORCE: