drawio-export/makefile

137 lines
3.9 KiB
Makefile
Raw Normal View History

# drawio-exporter makefile
# ========================
PROJECT_NAME := drawio-exporter
TMPDIR ?= $(CURDIR)/tmp
OUTDIR ?= $(CURDIR)/out
BINDIR ?= $(OUTDIR)/bin
VERSION ?= $(strip $(shell ./scripts/version.sh))
VERSION_NUMBER := $(strip $(shell ./scripts/version.sh number))
DIST_KIND := $(shell uname -m)
GO_OPT_BASE := -mod vendor -ldflags "-X main.version=${VERSION}"
GO_OPT ?=
EXPORT_RESULT ?= false # for CI please set EXPORT_RESULT to true
COVERAGE_FORMAT ?= html
GOCMD := go
GOTEST := $(GOCMD) test
GOVET := $(GOCMD) vet
ECHO_CMD := echo
ifeq ($(OS),Windows_NT)
DIST_SUFFIX := windows-$(DIST_KIND)
MSI_FILE := $(PROJECT_NAME)_$(VERSION)_$(DIST_KIND).msi
DIST_EXT := .zip
DIST_OPTS := -a -cf
ECHO_CMD := echo -e
else
PLATFORM := $(shell uname -s | tr '[:upper:]' '[:lower:]')
DIST_SUFFIX := $(PLATFORM)-$(DIST_KIND)
DIST_EXT := .tar.gz
DIST_OPTS := -czf
endif
PKG_NAME := $(PROJECT_NAME)_$(VERSION)_$(DIST_SUFFIX)
DIST_FILE := $(PKG_NAME)$(DIST_EXT)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
.PHONY: all version version-number test build dist vendor
version: ## Version of the project to be built
@echo $(VERSION)
version-number: ## Version number of the project to be built
@echo $(VERSION_NUMBER)
## Build:
all: clean vendor build ## Build binary
APPS = $(patsubst cmd/%/, %, $(dir $(wildcard cmd/*/main.go)))
build: $(addprefix $(BINDIR)/, $(APPS)) ## Build your project and put the output binary in out/bin/
@mkdir -p $(BINDIR)
@$(ECHO_CMD) "Build\t\t${GREEN}[OK]${RESET}"
$(BINDIR)/%: cmd/%/main.go $(patsubst cmd/%/main.go,cmd/%/*.go,$<)
GO111MODULE=on $(GOCMD) build $(GO_OPT_BASE) $(GO_OPT) \
-o $(BINDIR)/$(BIN_PREFIX)$(patsubst cmd/%/main.go,%,$<)$(BIN_SUFFIX) \
$(patsubst %/main.go,./%,$<)
dist: ## Create all distro packages
@rm -f "$(OUTDIR)/$(DIST_FILE)"
tar $(DIST_OPTS) "$(OUTDIR)/$(DIST_FILE)" -C "$(OUTDIR)" bin
@$(ECHO_CMD) "Dist\t\t${GREEN}[OK]${RESET}"
vendor: ## Copy of all packages needed to support builds and tests in the vendor directory.
$(GOCMD) mod vendor
@echo "Vendor\t\t${GREEN}[OK]${RESET}"
clean: ## Remove build related files
@rm -fr $(TMPDIR)
@rm -fr $(OUTDIR)
@rm -fr dist/
@$(ECHO_CMD) "Clean\t\t${GREEN}[OK]${RESET}"
## Test:
test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
@mkdir -p $(OUTDIR)
$(eval OUTPUT_OPTIONS = | go-junit-report -set-exit-code > $(OUTDIR)/junit-report.xml)
endif
$(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS)
@echo "Test\t\t${GREEN}[OK]${RESET}"
coverage: ## Run the tests of the project and export the coverage report.
@mkdir -p out
$(GOTEST) -cover -covermode=count -coverprofile=$(OUTDIR)/profile.cov ./...
$(GOCMD) tool cover -func $(OUTDIR)/profile.cov
ifeq ($(EXPORT_RESULT), true)
ifeq ($(COVERAGE_FORMAT), html)
gocov convert $(OUTDIR)/profile.cov | gocov-html > $(OUTDIR)/coverage.html
else
gocov convert $(OUTDIR)/profile.cov | gocov-xml > $(OUTDIR)/coverage.xml
endif
endif
@echo "Coverage\t${GREEN}[OK]${RESET}"
## Lint:
lint: lint-go ## Run all available linters.
@echo "Lint\t\t${GREEN}[OK]${RESET}"
lint-go:
go fmt ./...
go vet ./...
## Documentation:
doc: doc-golds ## Generate all documents.
@echo "Doc\t\t${GREEN}[OK]${RESET}"
doc-common:
@mkdir -p $(DOC_DIR)
doc-golds: doc-common ## Generate HTML documentation with Golds.
@mkdir -p $(DOC_DIR)/html
golds -gen -dir=$(DOC_DIR)/html -nouses -source-code-reading=rich \
-silent -only-list-exporteds -wdpkgs-listing=solo ./pkg/hexgrid
## Help:
help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)