2022-04-25 13:54:18 +00:00
|
|
|
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
2024-08-19 02:26:52 +00:00
|
|
|
GOFUMPT_PACKAGE_VERSION := v0.7.0
|
2022-04-25 13:54:18 +00:00
|
|
|
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
2024-08-26 01:03:16 +00:00
|
|
|
GOLANGCI_LINT_PACKAGE_VERSION := v1.60.3
|
2022-04-25 13:54:18 +00:00
|
|
|
|
2023-12-19 08:19:23 +00:00
|
|
|
EXECUTABLE := wp-ansible
|
|
|
|
|
2022-04-25 13:54:18 +00:00
|
|
|
DIST := dist
|
|
|
|
DIST_DIRS := $(DIST)
|
2023-12-19 08:19:23 +00:00
|
|
|
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
GO ?= go
|
|
|
|
CWD ?= $(shell pwd)
|
|
|
|
PACKAGES ?= $(shell go list ./...)
|
|
|
|
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-30 07:59:02 +00:00
|
|
|
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
2022-04-25 13:54:18 +00:00
|
|
|
|
2024-02-07 21:32:22 +00:00
|
|
|
XGO_VERSION := go-1.22.x
|
2023-10-30 10:40:39 +00:00
|
|
|
XGO_TARGETS ?= linux/amd64,linux/arm64
|
2022-04-25 13:54:18 +00:00
|
|
|
|
2023-12-19 08:19:23 +00:00
|
|
|
TARGETOS ?= linux
|
|
|
|
TARGETARCH ?= amd64
|
|
|
|
ifneq ("$(TARGETVARIANT)","")
|
|
|
|
GOARM ?= $(subst v,,$(TARGETVARIANT))
|
|
|
|
endif
|
2022-04-25 13:54:18 +00:00
|
|
|
TAGS ?= netgo
|
|
|
|
|
|
|
|
ifndef VERSION
|
2023-12-19 08:19:23 +00:00
|
|
|
ifneq ($(CI_COMMIT_TAG),)
|
|
|
|
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
|
2022-04-25 13:54:18 +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
|
2023-12-19 08:19:23 +00:00
|
|
|
all: clean build
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
$(GO) clean -i ./...
|
2023-12-19 08:19:23 +00:00
|
|
|
rm -rf $(DIST_DIRS)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2023-12-19 08:19:23 +00:00
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
2024-05-05 11:03:29 +00:00
|
|
|
$(GO) generate $(PACKAGES)
|
2023-12-22 09:10:39 +00:00
|
|
|
|
2022-04-25 13:54:18 +00:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2023-12-19 08:19:23 +00:00
|
|
|
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
.PHONY: build
|
2023-12-19 08:19:23 +00:00
|
|
|
build: $(DIST)/$(EXECUTABLE)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
2023-12-19 08:19:23 +00:00
|
|
|
$(DIST)/$(EXECUTABLE): $(SOURCES)
|
|
|
|
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
$(DIST_DIRS):
|
2023-12-19 08:19:23 +00:00
|
|
|
mkdir -p $(DIST_DIRS)
|
2022-04-25 13:54:18 +00:00
|
|
|
|
|
|
|
.PHONY: xgo
|
|
|
|
xgo: | $(DIST_DIRS)
|
2023-12-19 08:19:23 +00:00
|
|
|
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
|
2022-04-25 13:54:18 +00:00
|
|
|
cp /build/* $(CWD)/$(DIST)
|
|
|
|
ls -l $(CWD)/$(DIST)
|
|
|
|
|
|
|
|
.PHONY: checksum
|
|
|
|
checksum:
|
2023-12-19 08:19:23 +00:00
|
|
|
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
2022-04-25 13:54:18 +00:00
|
|
|
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-30 07:59:02 +00:00
|
|
|
$(GO) install $(GOTESTSUM_PACKAGE)
|