mirror of
https://github.com/foomo/gotsrpc.git
synced 2026-07-04 00:30:07 +00:00
188 lines
4.9 KiB
Makefile
188 lines
4.9 KiB
Makefile
.DEFAULT_GOAL:=help
|
|
-include .makerc
|
|
|
|
# --- Config -----------------------------------------------------------------
|
|
|
|
GOMODS=$(shell find . -type f -name go.mod)
|
|
# Newline hack for error output
|
|
define br
|
|
|
|
|
|
endef
|
|
|
|
# --- Targets -----------------------------------------------------------------
|
|
|
|
# This allows us to accept extra arguments
|
|
%: .mise .husky go.work
|
|
@:
|
|
|
|
# Ensure go.work file
|
|
go.work:
|
|
@go work init
|
|
@go work use -r .
|
|
@go work sync
|
|
|
|
.PHONY: .mise
|
|
# Install dependencies
|
|
.mise: msg := $(br)$(br)Please ensure you have 'mise' installed and activated!$(br)$(br)$$ brew update$(br)$$ brew install mise$(br)$(br)See the documentation: https://mise.jdx.dev/getting-started.html$(br)$(br)
|
|
.mise:
|
|
ifeq (, $(shell command -v mise))
|
|
$(error ${msg})
|
|
endif
|
|
@mise install
|
|
|
|
.PHONY: .husky
|
|
# Configure git hooks for husky
|
|
.husky:
|
|
@git config core.hooksPath .husky
|
|
|
|
### Tasks
|
|
|
|
.PHONY: check
|
|
## Run lint & test
|
|
check: tidy examples lint test
|
|
|
|
.PHONY: tidy
|
|
## Run go mod tidy
|
|
tidy:
|
|
@echo "〉go mod tidy"
|
|
@$(foreach mod,$(GOMODS), (cd $(dir $(mod)) && echo "📂 $(dir $(mod))" && go mod tidy) &&) true
|
|
|
|
.PHONY: lint
|
|
## Run linter
|
|
lint:
|
|
@echo "〉golangci-lint run"
|
|
@$(foreach mod,$(GOMODS), (cd $(dir $(mod)) && echo "📂 $(dir $(mod))" && golangci-lint run) &&) true
|
|
|
|
.PHONY: lint.fix
|
|
## Fix lint violations
|
|
lint.fix:
|
|
@echo "〉golangci-lint run fix"
|
|
@$(foreach mod,$(GOMODS), (cd $(dir $(mod)) && echo "📂 $(dir $(mod))" && golangci-lint run --fix) &&) true
|
|
|
|
.PHONY: test
|
|
## Run tests
|
|
test: go.work
|
|
@echo "〉go test"
|
|
#@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -tags=safe work
|
|
@$(foreach mod,$(GOMODS), (cd $(dir $(mod)) && echo "📂 $(dir $(mod))" && GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -tags=safe ./...) &&) true
|
|
|
|
.PHONY: test.race
|
|
## Run tests with -race
|
|
test.race: go.work
|
|
@echo "〉go test -race"
|
|
GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -tags=safe -race work
|
|
|
|
.PHONY: test.nocache
|
|
## Run tests with -count=1
|
|
test.nocache: go.work
|
|
@echo "〉go test -count=1"
|
|
@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -tags=safe -count=1 work
|
|
|
|
.PHONY: test.bench
|
|
## Run tests with -bench
|
|
test.bench: go.work
|
|
@echo "〉go test -bench"
|
|
@GO_TEST_TAGS=-skip go test -tags=safe -bench=. -benchmem -count=10 work > .benchmark.txt | benchstat benchmark.txt .benchmark.txt
|
|
@rm .benchstat.txt
|
|
|
|
.PHONY: test.bench.update
|
|
## Run tests with -bench & update baseline.txt
|
|
test.bench.update: go.work
|
|
@echo "〉go test -bench (updating baseline)"
|
|
@GO_TEST_TAGS=-skip go test -tags=safe -bench=. -benchmem -count=10 work > benchmark.txt
|
|
@echo "✅ benchmark.txt updated"
|
|
|
|
.PHONY: outdated
|
|
## Show outdated direct dependencies
|
|
outdated:
|
|
@echo "〉go mod outdated"
|
|
@go list -u -m -json all | go-mod-outdated -update -direct
|
|
|
|
.PHONY: build
|
|
## Build binary
|
|
build:
|
|
@echo "〉go build bin/gotsrpc"
|
|
@rm -f bin/gotsrpc
|
|
@go build -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: build.debug
|
|
## Build binary in debug mode
|
|
build.debug:
|
|
@echo "〉go build bin/gotsrpc (debug)"
|
|
@rm -f bin/gotsrpc
|
|
@go build -gcflags "all=-N -l" -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: install
|
|
## Run go install
|
|
install:
|
|
@echo "〉installing gotsrpc"
|
|
@go install cmd/gotsrpc/gotsrpc.go
|
|
|
|
.PHONY: install.debug
|
|
## Run go install with debug
|
|
install.debug:
|
|
@echo "〉installing gotsrpc (debug)"
|
|
@go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go
|
|
|
|
EXAMPLES=basic context errors monitor nullable union time types
|
|
define examples
|
|
.PHONY: example.$(1)
|
|
example.$(1):
|
|
@echo "📝 example: ${1}"
|
|
@cd example/${1} && go run ../../cmd/gotsrpc/gotsrpc.go gotsrpc.yml
|
|
@-cd example/${1}/client && ../../node_modules/.bin/tsc --build
|
|
|
|
.PHONY: example.$(1).run
|
|
example.$(1).run: example.${1}
|
|
@cd example/${1} && go run main.go
|
|
|
|
.PHONY: example.$(1).debug
|
|
example.$(1).debug: build.debug
|
|
@cd example/${1} && dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ../../bin/gotsrpc gotsrpc.yml
|
|
endef
|
|
$(foreach p,$(EXAMPLES),$(eval $(call examples,$(p))))
|
|
|
|
.PHONY: generate
|
|
## Run go generate
|
|
generate:
|
|
@echo "〉go generate"
|
|
@go generate ./...
|
|
|
|
.PHONY: examples
|
|
## Generate examples
|
|
examples:
|
|
@echo "〉Generating examples"
|
|
@for name in example/*/; do\
|
|
if [ $$name != "example/node_modules/" ]; then \
|
|
$(MAKE) example.`basename $${name}`;\
|
|
fi \
|
|
done
|
|
.PHONY: examples
|
|
|
|
### Utils
|
|
|
|
.PHONY: docs
|
|
## Open go docs
|
|
docs:
|
|
@go doc -http
|
|
|
|
.PHONY: help
|
|
## Show help text
|
|
help:
|
|
@echo "gotsrpc\n"
|
|
@echo "Usage:\n make [task]"
|
|
@awk '{ \
|
|
if($$0 ~ /^### /){ \
|
|
if(help) printf "%-23s %s\n\n", cmd, help; help=""; \
|
|
printf "\n%s:\n", substr($$0,5); \
|
|
} else if($$0 ~ /^[a-zA-Z0-9._-]+:/){ \
|
|
cmd = substr($$0, 1, index($$0, ":")-1); \
|
|
if(help) printf " %-23s %s\n", cmd, help; help=""; \
|
|
} else if($$0 ~ /^##/){ \
|
|
help = help ? help "\n " substr($$0,3) : substr($$0,3); \
|
|
} else if(help){ \
|
|
print "\n " help "\n"; help=""; \
|
|
} \
|
|
}' $(MAKEFILE_LIST)
|