diff --git a/Makefile b/Makefile index 95faa46..698d34a 100644 --- a/Makefile +++ b/Makefile @@ -3,54 +3,15 @@ GOFUMPT_PACKAGE_VERSION := v0.5.0 # renovate: datasource=github-releases depName=golangci/golangci-lint GOLANGCI_LINT_PACKAGE_VERSION := v1.55.2 -EXECUTABLE := wp-plugin-go - -DIST := dist -DIST_DIRS := $(DIST) -IMPORT := github.com/thegeeklab/$(EXECUTABLE) - 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 GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest GENERATE ?= -XGO_VERSION := go-1.21.x -XGO_TARGETS ?= linux/amd64,linux/arm64,linux/arm-6,linux/arm-7 - -TARGETOS ?= linux -TARGETARCH ?= amd64 -ifneq ("$(TARGETVARIANT)","") -GOARM ?= $(subst v,,$(TARGETVARIANT)) -endif -TAGS ?= netgo - -ifndef VERSION - ifneq ($(CI_COMMIT_TAG),) - VERSION ?= $(subst v,,$(CI_COMMIT_TAG)) - 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: @@ -71,33 +32,9 @@ generate: test: $(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES) -.PHONY: build -build: $(DIST)/$(EXECUTABLE) - -$(DIST)/$(EXECUTABLE): $(SOURCES) - GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE) - -$(DIST_DIRS): - mkdir -p $(DIST_DIRS) - -.PHONY: xgo -xgo: | $(DIST_DIRS) - $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) . - 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) $(GO) install $(GOTESTSUM_PACKAGE) diff --git a/docs/docs.go b/docs/docs.go index 9dfef19..c775e63 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -7,6 +7,8 @@ import ( "sort" "strings" + wp_template "github.com/thegeeklab/wp-plugin-go/template" + "github.com/urfave/cli/v2" ) @@ -34,7 +36,7 @@ var templateFs embed.FS func ToMarkdown(app *cli.App) (string, error) { var w bytes.Buffer - tpls, err := template.New("cli").ParseFS(templateFs, "**/*.tmpl") + tpls, err := template.New("cli").Funcs(wp_template.LoadFuncMap()).ParseFS(templateFs, "**/*.tmpl") if err != nil { return "", err } diff --git a/template/functions.go b/template/functions.go index f0f42d1..4c5b521 100644 --- a/template/functions.go +++ b/template/functions.go @@ -6,7 +6,7 @@ import ( "github.com/Masterminds/sprig/v3" ) -func loadFuncMap() template.FuncMap { +func LoadFuncMap() template.FuncMap { sprigFuncs := sprig.GenericFuncMap() customFuncs := template.FuncMap{} diff --git a/template/template.go b/template/template.go index b715f55..dfdb28d 100644 --- a/template/template.go +++ b/template/template.go @@ -25,7 +25,7 @@ import ( func Render(ctx context.Context, client http.Client, templateString string, payload interface{}) (string, error) { var outString bytes.Buffer - tpl := new(template.Template).Funcs(loadFuncMap()) + tpl := new(template.Template).Funcs(LoadFuncMap()) templateURL, err := url.Parse(templateString) if err == nil {