Files
mtusi2026lab2/Makefile
T
Vladislav Kunetskiy 1e38dbdf35
Application / Lint (pull_request) Canceled after 0s
Application / Unit tests (pull_request) Canceled after 0s
Application / Docker build (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
lab2
2026-10-06 18:58:40 +03:00

110 lines
3.1 KiB
Makefile

PYTHON ?= python3
BASE_URL ?= http://localhost:8080
CA_FILE ?=
ACTION_SCRIPT ?=
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)
PYTHON_LOCAL = env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 $(PYTHON)
.PHONY: help check validate test load test-persistence smoke-local load-local
help:
@echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes"
check:
$(PYTHON) scripts/check_contract.py
validate:
$(PYTHON) scripts/validate_openapi.py
test:
$(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
load:
$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
test-persistence:
@test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2)
$(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS)
smoke-local:
$(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS)
load-local:
$(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)
.DEFAULT_GOAL := help
GO ?= go
APP_NAME ?= messenger
CMD_PKG := ./cmd/$(APP_NAME)
LOCAL_BIN := $(CURDIR)/bin
GOLANGCI_LINT_VERSION ?= v2.13.2
GOLANGCI_LINT := $(LOCAL_BIN)/golangci-lint
OPENAPI_SPEC := contracts/openapi.json
OGEN_CONFIG := .ogen.yml
OAS_DIR := internal/transport/rest/internal/oas
-include .env
export
.PHONY: unit-test
unit-test:
$(GO) test -race -shuffle=on -count=1 -timeout=5m ./...
.PHONY: integration-test
integration-test:
$(GO) test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis
.PHONY: test-db-up test-db-down
test-db-up:
@docker-compose -f docker-compose.local.yaml up -d --wait postgres redis
test-db-down:
@docker-compose -f docker-compose.local.yaml down
# не учитываем генеренные файлы, также cmd в подсчете покрытия
COVER_EXCLUDE ?= /(mocks|oas)/|/cmd/
.PHONY: cover
cover:
$(GO) test -race -shuffle=on -count=1 -timeout=5m \
-covermode=atomic -coverprofile=coverage.out.tmp ./...
@grep -Ev '$(COVER_EXCLUDE)' coverage.out.tmp > coverage.out
@rm coverage.out.tmp
$(GO) tool cover -func=coverage.out | tail -n 1
$(GO) tool cover -html=coverage.out
.PHONY: generate
generate: generate-api generate-mocks sqlc
.PHONY: generate-api
generate-api:
$(GO) tool ogen --config $(OGEN_CONFIG) --target $(OAS_DIR) --package oas --clean $(OPENAPI_SPEC)
.PHONY: generate-mocks
generate-mocks:
$(GO) tool mockery
.PHONY: sqlc
sqlc:
$(GO) tool sqlc generate
.PHONY: dev-up dev-down dev-reload
dev-up:
@docker-compose -f docker-compose.local.yaml up -d --build
dev-down:
@docker-compose -f docker-compose.local.yaml down
dev-reload:
@docker-compose -f docker-compose.local.yaml up -d --build --force-recreate
.PHONY: migrate
migrate:
$(GO) run ./cmd/migrate up
$(GOLANGCI_LINT):
GOBIN=$(LOCAL_BIN) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v