Files
gocqlx/Makefile

115 lines
2.9 KiB
Makefile
Raw Normal View History

2018-08-07 15:30:04 +02:00
all: check test
2017-07-21 15:13:09 +02:00
ifndef SCYLLA_IMAGE
2025-04-24 14:02:37 -04:00
SCYLLA_IMAGE := scylladb/scylla
2018-07-28 06:41:33 +02:00
endif
ifndef SCYLLA_CPU
SCYLLA_CPU := 0
endif
ifndef GOTEST_CPU
GOTEST_CPU := 1
endif
ifndef GOPATH
GOPATH := $(shell go env GOPATH)
endif
ifndef GOBIN
GOBIN := $(GOPATH)/bin
endif
export PATH := $(GOBIN):$(PATH)
GOOS := $(shell uname | tr '[:upper:]' '[:lower:]')
GOARCH := $(shell go env GOARCH)
GOLANGCI_VERSION := 2.5.0
ifeq ($(GOARCH),arm64)
GOLANGCI_DOWNLOAD_URL := "https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-arm64.tar.gz"
else ifeq ($(GOARCH),amd64)
GOLANGCI_DOWNLOAD_URL := "https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-amd64.tar.gz"
else
@printf 'Unknown architecture "%s"\n', "$(GOARCH)"
@exit 69
endif
2018-08-07 15:30:04 +02:00
2018-07-28 06:41:33 +02:00
.PHONY: fmt
2018-08-07 15:30:04 +02:00
fmt:
2018-07-28 06:41:33 +02:00
@go fmt ./...
2017-07-21 15:13:09 +02:00
.PHONY: check
check: .require-golangci-lint
@golangci-lint run ./...
2018-05-22 14:47:43 +02:00
.PHONY: fix
fix: .require-golangci-lint .require-fieldalignment
@$(MAKE) fmt
@golangci-lint run --fix ./...
@fieldalignment -test=false -fix ./...
GOTEST := go test -cpu $(GOTEST_CPU) -count=1 -cover -race -tags all
2018-05-25 11:02:52 +02:00
2017-07-21 15:13:09 +02:00
.PHONY: test
test: start-scylla
2024-06-26 13:32:47 -04:00
echo "==> Running tests..."
echo "==> Running tests... in ."
2018-05-25 11:02:52 +02:00
@$(GOTEST) .
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./qb"
2018-05-25 11:02:52 +02:00
@$(GOTEST) ./qb
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./table"
@$(GOTEST) ./table
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./migrate"
@$(GOTEST) ./migrate
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./dbutil"
@$(GOTEST) ./dbutil
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./cmd/schemagen"
2021-11-17 11:56:21 +01:00
@$(GOTEST) ./cmd/schemagen
2024-06-26 13:32:47 -04:00
echo "==> Running tests... in ./cmd/schemagen/testdata"
@cd ./cmd/schemagen/testdata ; go mod tidy ; $(GOTEST) .; cd ../../..
2018-05-22 16:40:31 +02:00
.PHONY: bench
bench:
@go test -cpu $(GOTEST_CPU) -tags all -run=XXX -bench=. -benchmem ./...
.PHONY: run-examples
run-examples:
2020-12-03 12:52:48 +01:00
@go test -tags all -v -run=Example ./...
.PHONY: start-scylla
start-scylla:
@echo "==> Running test instance of Scylla $(SCYLLA_IMAGE)"
@docker pull $(SCYLLA_IMAGE)
@docker run --name gocqlx-scylla -p 9042:9042 --cpuset-cpus=$(SCYLLA_CPU) --memory 1G --rm -d $(SCYLLA_IMAGE)
@until docker exec gocqlx-scylla cqlsh -e "DESCRIBE SCHEMA"; do sleep 2; done
.PHONY: stop-scylla
stop-scylla:
@docker stop gocqlx-scylla
2017-07-21 15:13:09 +02:00
.PHONY: get-deps
get-deps:
@go mod download
2018-05-22 14:47:43 +02:00
.PHONY: get-tools
get-tools:
@echo "==> Installing tools at $(GOBIN)..."
@$(MAKE) install-golangci-lint
.require-golangci-lint:
ifeq ($(shell if golangci-lint --version 2>/dev/null | grep ${GOLANGCI_VERSION} 1>/dev/null 2>&1; then echo "ok"; else echo "need-install"; fi), need-install)
$(MAKE) install-golangci-lint
endif
install-golangci-lint:
@echo "==> Installing golangci-lint ${GOLANGCI_VERSION} at $(GOBIN)..."
$(call dl_tgz,golangci-lint,$(GOLANGCI_DOWNLOAD_URL))
define dl_tgz
@mkdir "$(GOBIN)" 2>/dev/null || true
@echo "Downloading $(GOBIN)/$(1)";
@curl --progress-bar -L $(2) | tar zxf - --wildcards --strip 1 -C $(GOBIN) '*/$(1)';
@chmod +x "$(GOBIN)/$(1)";
endef