2021-03-04 07:10:08 +08:00
|
|
|
SHELL := /bin/bash
|
|
|
|
BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
|
|
|
|
cat $(CURDIR)/.version 2> /dev/null || echo v0)
|
|
|
|
VERSION_HASH = $(shell git rev-parse HEAD)
|
|
|
|
|
|
|
|
BIN = $(BASE_PATH)/bin
|
|
|
|
PATH := $(BIN):$(PATH)
|
|
|
|
export PATH
|
|
|
|
|
|
|
|
# printing
|
|
|
|
V = 0
|
|
|
|
Q = $(if $(filter 1,$V),,@)
|
|
|
|
M = $(shell printf "\033[34;1m▶\033[0m")
|
|
|
|
|
|
|
|
GO = GOGC=off go
|
|
|
|
# go module
|
|
|
|
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
|
|
|
|
|
|
|
|
DATE ?= $(shell date +%FT%T%z)
|
|
|
|
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
|
|
|
|
cat $(CURDIR)/.version 2> /dev/null || echo v0)
|
2021-05-25 17:29:38 +08:00
|
|
|
VERSION_HASH = $(shell git rev-parse --short HEAD)
|
2021-03-04 07:10:08 +08:00
|
|
|
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
|
2021-05-25 17:29:38 +08:00
|
|
|
LDFLAGS += -X "$(MODULE)/version.Version=$(VERSION)" -X "$(MODULE)/version.CommitSHA=$(VERSION_HASH)"
|
2021-03-04 07:10:08 +08:00
|
|
|
|
|
|
|
# tools
|
|
|
|
$(BIN):
|
|
|
|
@mkdir -p $@
|
|
|
|
$(BIN)/%: | $(BIN) ; $(info $(M) installing $(PACKAGE)…)
|
|
|
|
$Q env GOBIN=$(BIN) $(GO) install $(PACKAGE)
|
|
|
|
|
|
|
|
GOLANGCI_LINT = $(BIN)/golangci-lint
|
2021-07-26 18:00:05 +08:00
|
|
|
$(BIN)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint@v1.41.1
|
2021-03-04 07:10:08 +08:00
|
|
|
|
|
|
|
GOIMPORTS = $(BIN)/goimports
|
2021-12-21 05:36:35 +08:00
|
|
|
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports@v0.1.8
|
2021-03-04 07:10:08 +08:00
|
|
|
|
|
|
|
## build: Build
|
|
|
|
.PHONY: build
|
|
|
|
build: | build-frontend build-backend ; $(info $(M) building…)
|
|
|
|
|
|
|
|
## build-frontend: Build frontend
|
|
|
|
.PHONY: build-frontend
|
|
|
|
build-frontend: | ; $(info $(M) building frontend…)
|
|
|
|
$Q cd frontend && npm ci && npm run build
|
|
|
|
|
|
|
|
## build-backend: Build backend
|
|
|
|
.PHONY: build-backend
|
2021-03-10 01:59:19 +08:00
|
|
|
build-backend: | ; $(info $(M) building backend…)
|
2021-03-15 21:02:30 +08:00
|
|
|
$Q $(GO) build -ldflags '$(LDFLAGS)' -o .
|
2021-03-04 07:10:08 +08:00
|
|
|
|
|
|
|
## test: Run all tests
|
|
|
|
.PHONY: test
|
|
|
|
test: | test-frontend test-backend ; $(info $(M) running tests…)
|
|
|
|
|
|
|
|
## test-frontend: Run frontend tests
|
|
|
|
.PHONY: test-frontend
|
|
|
|
test-frontend: | ; $(info $(M) running frontend tests…)
|
|
|
|
|
|
|
|
## test-backend: Run backend tests
|
|
|
|
.PHONY: test-backend
|
2021-03-15 21:02:30 +08:00
|
|
|
test-backend: | ; $(info $(M) running backend tests…)
|
2021-03-04 07:10:08 +08:00
|
|
|
$Q $(GO) test -v ./...
|
|
|
|
|
|
|
|
## lint: Lint
|
|
|
|
.PHONY: lint
|
|
|
|
lint: lint-frontend lint-backend lint-commits | ; $(info $(M) running all linters…)
|
|
|
|
|
|
|
|
## lint-frontend: Lint frontend
|
|
|
|
.PHONY: lint-frontend
|
|
|
|
lint-frontend: | ; $(info $(M) running frontend linters…)
|
|
|
|
$Q cd frontend && npm ci && npm run lint
|
|
|
|
|
|
|
|
## lint-backend: Lint backend
|
|
|
|
.PHONY: lint-backend
|
|
|
|
lint-backend: | $(GOLANGCI_LINT) ; $(info $(M) running backend linters…)
|
2021-12-21 05:36:35 +08:00
|
|
|
$Q $(GOLANGCI_LINT) run -v
|
2021-03-04 07:10:08 +08:00
|
|
|
|
|
|
|
## lint-commits: Lint commits
|
|
|
|
.PHONY: lint-commits
|
|
|
|
lint-commits: | ; $(info $(M) running commitlint…)
|
|
|
|
$Q ./scripts/commitlint.sh
|
|
|
|
|
2021-12-21 05:36:35 +08:00
|
|
|
## fmt: Format source files
|
|
|
|
fmt: $(GOIMPORTS)
|
|
|
|
$Q $(GOIMPORTS) -local $(MODULE) -w $$(find . -type f -name '*.go' -not -path "./vendor/*")
|
|
|
|
|
2021-03-04 07:10:08 +08:00
|
|
|
## bump-version: Bump app version
|
|
|
|
.PHONY: bump-version
|
|
|
|
bump-version: | ; $(info $(M) creating a new release…)
|
|
|
|
$Q ./scripts/bump_version.sh
|
|
|
|
|
|
|
|
## help: Show this help
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /' | sort
|