2022-04-25 10:55:06 +00:00
|
|
|
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
2024-08-19 03:54:38 +00:00
|
|
|
GOFUMPT_PACKAGE_VERSION := v0.7.0
|
2022-04-25 10:55:06 +00:00
|
|
|
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
2024-09-16 03:57:20 +00:00
|
|
|
GOLANGCI_LINT_PACKAGE_VERSION := v1.61.0
|
2024-10-02 13:44:18 +00:00
|
|
|
# renovate: datasource=docker depName=docker.io/techknowlogick/xgo
|
2024-10-03 12:29:31 +00:00
|
|
|
XGO_PACKAGE_VERSION := go-1.23.x
|
2022-04-25 10:55:06 +00:00
|
|
|
|
2023-08-15 22:15:24 +00:00
|
|
|
EXECUTABLE := wp-matrix
|
2022-04-25 10:55:06 +00:00
|
|
|
|
|
|
|
DIST := dist
|
|
|
|
DIST_DIRS := $(DIST)
|
|
|
|
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
|
|
|
|
|
|
|
GO ?= go
|
|
|
|
CWD ?= $(shell pwd)
|
2024-05-12 09:08:26 +00:00
|
|
|
PACKAGES ?= $(shell go list ./...)
|
2022-04-25 10:55:06 +00:00
|
|
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
|
|
|
|
|
|
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
|
|
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
|
|
|
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
2023-10-29 15:04:44 +00:00
|
|
|
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
2024-05-11 08:25:15 +00:00
|
|
|
MOCKERY_PACKAGE ?= github.com/vektra/mockery/v2@latest
|
2022-04-25 10:55:06 +00:00
|
|
|
|
2023-01-14 21:43:15 +00:00
|
|
|
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
2022-04-25 10:55:06 +00:00
|
|
|
|
2023-01-14 21:43:15 +00:00
|
|
|
TARGETOS ?= linux
|
|
|
|
TARGETARCH ?= amd64
|
|
|
|
ifneq ("$(TARGETVARIANT)","")
|
|
|
|
GOARM ?= $(subst v,,$(TARGETVARIANT))
|
|
|
|
endif
|
2022-04-25 10:55:06 +00:00
|
|
|
TAGS ?= netgo
|
|
|
|
|
|
|
|
ifndef VERSION
|
2023-08-15 22:15:24 +00:00
|
|
|
ifneq ($(CI_COMMIT_TAG),)
|
|
|
|
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
|
2022-04-25 10:55:06 +00:00
|
|
|
else
|
|
|
|
VERSION ?= $(shell git rev-parse --short HEAD)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef DATE
|
|
|
|
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
|
|
|
|
endif
|
|
|
|
|
|
|
|
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: clean build
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
$(GO) clean -i ./...
|
|
|
|
rm -rf $(DIST_DIRS)
|
|
|
|
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
|
|
|
$(GO) run $(GOFUMPT_PACKAGE) -extra -w $(SOURCES)
|
|
|
|
|
|
|
|
.PHONY: golangci-lint
|
|
|
|
golangci-lint:
|
|
|
|
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
|
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint: golangci-lint
|
|
|
|
|
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
2024-05-10 06:42:59 +00:00
|
|
|
$(GO) generate $(PACKAGES)
|
2024-05-11 08:25:15 +00:00
|
|
|
$(GO) run $(MOCKERY_PACKAGE)
|
2024-01-03 22:04:03 +00:00
|
|
|
|
2022-04-25 10:55:06 +00:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2023-10-29 15:04:44 +00:00
|
|
|
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
2022-04-25 10:55:06 +00:00
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
build: $(DIST)/$(EXECUTABLE)
|
|
|
|
|
|
|
|
$(DIST)/$(EXECUTABLE): $(SOURCES)
|
2023-01-14 21:58:37 +00:00
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
|
2022-04-25 10:55:06 +00:00
|
|
|
|
|
|
|
$(DIST_DIRS):
|
|
|
|
mkdir -p $(DIST_DIRS)
|
|
|
|
|
|
|
|
.PHONY: xgo
|
|
|
|
xgo: | $(DIST_DIRS)
|
2024-10-02 13:44:18 +00:00
|
|
|
$(GO) run $(XGO_PACKAGE) -go $(XGO_PACKAGE_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
|
2022-04-25 10:55:06 +00:00
|
|
|
cp /build/* $(CWD)/$(DIST)
|
|
|
|
ls -l $(CWD)/$(DIST)
|
|
|
|
|
|
|
|
.PHONY: checksum
|
|
|
|
checksum:
|
|
|
|
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
|
|
ls -l $(CWD)/$(DIST)
|
|
|
|
|
|
|
|
.PHONY: release
|
|
|
|
release: xgo checksum
|
|
|
|
|
|
|
|
.PHONY: deps
|
|
|
|
deps:
|
|
|
|
$(GO) mod download
|
|
|
|
$(GO) install $(GOFUMPT_PACKAGE)
|
|
|
|
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
|
|
|
$(GO) install $(XGO_PACKAGE)
|
2023-10-29 15:04:44 +00:00
|
|
|
$(GO) install $(GOTESTSUM_PACKAGE)
|