soundwerft/Makefile

124 lines
3.6 KiB
Makefile

.DEFAULT_GOAL: all
.PHONY: all
all: generate check build ## Build and test the complete project
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ General
.PHONY: build
build: vendor ## Build the project locally
go build -o bin/soundwerft ./cmd
.PHONY: check
check: test ## Run all tests and linters
.PHONY: test
test: vendor test-unit ## Run all tests
.PHONY: test-unit
test-unit: vendor ## Run all unit tests
go test ./... -cover -coverprofile=coverage.out -race --tags=unit
.PHONY: clean
clean: ## Clean generated files
find . -type f -name '*_templ.go' -delete
.PHONY: clean/all
clean/all: clean ## Clean all generated and downloaded files, including binaries and vendor
rm -rf bin
rm -rf vendor
.PHONY: run
run: ## Run the app
go run cmd/main.go -c local.env
.PHONY: generate
generate: i18n/extract templ/generate ## Generate code from go:generate annotations
go generate ./...
.PHONY: watch
watch: vendor reflex ## Run the application and restart when files change
$(REFLEX) -c reflex.conf
*_templ.go:
$(TEMPL) generate
vendor: go.mod *_templ.go
go mod vendor
.PHONY: i18n/extract
i18n/extract: goi18n
$(GOI18N) extract -sourceLanguage en -outdir "pkg/localizer/messages"
.PHONY: templ/generate
templ/generate: templ
$(TEMPL) generate
##@ Database actions
DB_VENDOR ?= postgres
DB_PASSWD ?= postgres
DB_USER ?= postgres
DB_NAME ?= soundwerft
.PHONY: db/up
db/up: db/up/$(DB_VENDOR) ## Start local Database as docker container. Use `DB_VENDOR` to set specific vendor (default: postgres)
.PHONY: db/down
db/down: db/down/$(DB_VENDOR) ## Stop locally running Database docker container. Use `DB_VENDOR` to set specific vendor (default: postgres)
.PHONY: db/restart
db/restart: db/down/$(DB_VENDOR) db/up/$(DB_VENDOR) ## Restart the local database
.PHONY: db/up/postgres
db/up/postgres:
docker run --rm --name $(DB_NAME)-pg -e POSTGRES_USER=$(DB_USER) -e POSTGRES_PASSWORD=$(DB_PASSWD) -p 5432:5432 -d postgres
.PHONY: db/down/postgres
db/down/postgres:
-docker stop $$(docker ps -qf "name=$(DB_NAME)-pg")
.PHONY: db/migration
db/migration: migrate ## Create a new database migration under db/$(DB_VENDOR)
$(MIGRATE) create -ext sql -dir internal/repository/$(DB_VENDOR)/migrations -seq -digits 4 new-migration
##@ Tools
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
REFLEX ?= $(LOCALBIN)/reflex
REFLEX_VERSION ?= latest
reflex: $(REFLEX) ## Download reflex binary locally if necessary
$(REFLEX): $(LOCALBIN)
test -s $(REFLEX) || GOBIN=$(LOCALBIN) go install github.com/cespare/reflex@$(REFLEX_VERSION)
GOI18N ?= $(LOCALBIN)/goi18n
GOI18N_VERSION ?= latest
goi18n: $(GOI18N) ## Download go18n binary locally if necessary
$(GOI18N): $(LOCALBIN)
test -s $(GOI18N) || GOBIN=$(LOCALBIN) go install -v github.com/nicksnyder/go-i18n/v2/goi18n@$(GOI18N_VERSION)
TEMPL ?= $(LOCALBIN)/templ
TEMPL_VERSION ?= latest
templ: $(TEMPL) ## Download templ binary locally if necessary
$(TEMPL): $(LOCALBIN)
test -s $(TEMPL) || GOBIN=$(LOCALBIN) go install -v github.com/a-h/templ/cmd/templ@$(TEMPL_VERSION)
MIGRATE ?= $(LOCALBIN)/migrate
MIGRATE_VERSION ?= latest
REFLEX ?= $(LOCALBIN)/reflex
REFLEX_VERSION ?= latest
.PHONY: migrate
migrate: $(MIGRATE) ## Download migrate binary locally if necessary
$(MIGRATE): $(LOCALBIN)
test -s $(LOCALBIN)/migrate || GOBIN=$(LOCALBIN) go install github.com/golang-migrate/migrate/v4/cmd/migrate@$(MIGRATE_VERSION)