Refactor Makefile tools installation (#313)
* Refactor Makefile tools installation Updating tools is not easy due to the bad Makefile design Make it easier to update tools, preparing to golang and gocql update. * Apply make fix * Cleanup github workflow
This commit is contained in:
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -13,7 +13,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
SCYLLA_IMAGE: scylladb/scylla
|
SCYLLA_IMAGE: scylladb/scylla
|
||||||
GOBIN: ./bin
|
|
||||||
steps:
|
steps:
|
||||||
- name: Git Checkout
|
- name: Git Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -33,9 +32,6 @@ jobs:
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-go-
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
- name: Make Directory for GOBIN
|
|
||||||
run: mkdir -p "${GOBIN}"
|
|
||||||
|
|
||||||
- name: Download Dependencies
|
- name: Download Dependencies
|
||||||
run: git --version && make get-deps && make get-tools
|
run: git --version && make get-deps && make get-tools
|
||||||
|
|
||||||
|
|||||||
60
Makefile
60
Makefile
@@ -19,20 +19,36 @@ endif
|
|||||||
ifndef GOBIN
|
ifndef GOBIN
|
||||||
GOBIN := $(GOPATH)/bin
|
GOBIN := $(GOPATH)/bin
|
||||||
endif
|
endif
|
||||||
|
export PATH := $(GOBIN):$(PATH)
|
||||||
|
|
||||||
|
GOOS := $(shell uname | tr '[:upper:]' '[:lower:]')
|
||||||
|
GOARCH := $(shell go env GOARCH)
|
||||||
|
|
||||||
|
GOLANGCI_VERSION := 1.64.8
|
||||||
|
FIELDALIGNMENT_VERSION := 0.11.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
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
@go fmt ./...
|
@go fmt ./...
|
||||||
|
|
||||||
.PHONY: check
|
.PHONY: check
|
||||||
check:
|
check: .require-golangci-lint
|
||||||
@$(GOBIN)/golangci-lint run ./...
|
@golangci-lint run ./...
|
||||||
|
|
||||||
.PHONY: fix
|
.PHONY: fix
|
||||||
fix:
|
fix: .require-golangci-lint .require-fieldalignment
|
||||||
@$(GOBIN)/golangci-lint run --fix ./...
|
@$(MAKE) fmt
|
||||||
@fieldalignment -V=full >/dev/null 2>&1 || go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v0.11.0
|
@golangci-lint run --fix ./...
|
||||||
@$(GOBIN)/fieldalignment -test=false -fix ./...
|
@fieldalignment -test=false -fix ./...
|
||||||
|
|
||||||
GOTEST := go test -cpu $(GOTEST_CPU) -count=1 -cover -race -tags all
|
GOTEST := go test -cpu $(GOTEST_CPU) -count=1 -cover -race -tags all
|
||||||
|
|
||||||
@@ -77,11 +93,33 @@ stop-scylla:
|
|||||||
get-deps:
|
get-deps:
|
||||||
@go mod download
|
@go mod download
|
||||||
|
|
||||||
define dl_tgz
|
|
||||||
@curl -sSq -L $(2) | tar zxf - --strip 1 -C $(GOBIN) --wildcards '*/$(1)'
|
|
||||||
endef
|
|
||||||
|
|
||||||
.PHONY: get-tools
|
.PHONY: get-tools
|
||||||
get-tools:
|
get-tools:
|
||||||
@echo "==> Installing tools at $(GOBIN)..."
|
@echo "==> Installing tools at $(GOBIN)..."
|
||||||
@$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v1.59.1/golangci-lint-1.59.1-linux-amd64.tar.gz)
|
@$(MAKE) install-golangci-lint
|
||||||
|
@$(MAKE) install-fieldalignment
|
||||||
|
|
||||||
|
.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))
|
||||||
|
|
||||||
|
.require-fieldalignment:
|
||||||
|
ifeq ($(shell if fieldalignment -V=full 1>/dev/null 2>&1; then echo "ok"; else echo "need-install"; fi), need-install)
|
||||||
|
$(MAKE) install-golangci-lint
|
||||||
|
endif
|
||||||
|
|
||||||
|
install-fieldalignment:
|
||||||
|
@echo "==> Installing fieldalignment ${FIELDALIGNMENT_VERSION} at $(GOBIN)..."
|
||||||
|
@go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v${FIELDALIGNMENT_VERSION}
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
14
qb/update.go
14
qb/update.go
@@ -31,13 +31,13 @@ func (a assignment) writeCql(cql *bytes.Buffer) (names []string) {
|
|||||||
|
|
||||||
// UpdateBuilder builds CQL UPDATE statements.
|
// UpdateBuilder builds CQL UPDATE statements.
|
||||||
type UpdateBuilder struct {
|
type UpdateBuilder struct {
|
||||||
table string
|
table string
|
||||||
assignments []assignment
|
assignments []assignment
|
||||||
where where
|
where where
|
||||||
_if _if
|
_if _if
|
||||||
using using
|
using using
|
||||||
exists bool
|
exists bool
|
||||||
allowFiltering bool
|
allowFiltering bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update returns a new UpdateBuilder with the given table name.
|
// Update returns a new UpdateBuilder with the given table name.
|
||||||
|
|||||||
Reference in New Issue
Block a user