forked from kfzteile24/postgresql-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
73 lines (63 loc) · 2.67 KB
/
Copy pathMakefile
File metadata and controls
73 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
VENV_DIR ?= .venv
VENV_RUN = . $(VENV_DIR)/bin/activate
PIP_CMD ?= pip
PYTHON_CMD ?= python
TEST_DEPS ?= pytest pytest-timeout
LINT_DEPS ?= ruff
PG_TEST_CONTAINER ?= pg-proxy-local-tests
PG_TEST_IMAGE ?= postgres:16
PG_TEST_PORT ?= 55432
PG_TEST_USER ?= postgres
PG_TEST_PASSWORD ?= postgres
PG_TEST_DB ?= postgres
ACT_CMD ?= act
ACT_WORKFLOW ?= .github/workflows/tests.yml
ACT_JOB ?= tests
ACT_PULL ?= false
ACT_CONTAINER_ARCH ?= linux/arm64
usage: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
install: ## Install dependencies in local virtualenv folder
(test `which virtualenv` || $(PIP_CMD) install virtualenv) && \
(test -e $(VENV_DIR) || virtualenv $(VENV_OPTS) $(VENV_DIR)) && \
($(VENV_RUN) && $(PIP_CMD) install --upgrade pip) && \
(test ! -e requirements.txt || ($(VENV_RUN); $(PIP_CMD) install -r requirements.txt))
publish: ## Publish the library to the central PyPi repository
($(VENV_RUN); pip install twine; python ./setup.py sdist && twine upload dist/*)
install-test: install ## Install test dependencies in local virtualenv
($(VENV_RUN); $(PIP_CMD) install $(TEST_DEPS))
install-lint: install ## Install lint dependencies in local virtualenv
($(VENV_RUN); $(PIP_CMD) install $(LINT_DEPS))
lint: install-lint ## Format code with ruff
$(VENV_DIR)/bin/ruff format postgresql_proxy tests plugins
test: ## Start local PostgreSQL container and run all tests
@set -euo pipefail; \
cleanup() { docker rm -f $(PG_TEST_CONTAINER) >/dev/null 2>&1 || true; }; \
trap cleanup EXIT INT TERM; \
docker rm -f $(PG_TEST_CONTAINER) >/dev/null 2>&1 || true; \
docker run --name $(PG_TEST_CONTAINER) \
-e POSTGRES_USER=$(PG_TEST_USER) \
-e POSTGRES_PASSWORD=$(PG_TEST_PASSWORD) \
-e POSTGRES_DB=$(PG_TEST_DB) \
-p $(PG_TEST_PORT):5432 \
-d $(PG_TEST_IMAGE) >/dev/null; \
for i in $$(seq 1 45); do \
if docker exec $(PG_TEST_CONTAINER) pg_isready -U $(PG_TEST_USER) >/dev/null 2>&1; then \
echo "PostgreSQL ready on 127.0.0.1:$(PG_TEST_PORT)"; \
break; \
fi; \
sleep 1; \
done; \
if ! docker exec $(PG_TEST_CONTAINER) pg_isready -U $(PG_TEST_USER) >/dev/null 2>&1; then \
echo "PostgreSQL did not become ready in time"; \
exit 1; \
fi; \
E2E_PG_HOST=127.0.0.1 \
E2E_PG_PORT=$(PG_TEST_PORT) \
E2E_PG_USER=$(PG_TEST_USER) \
E2E_PG_PASSWORD=$(PG_TEST_PASSWORD) \
E2E_PG_DB=$(PG_TEST_DB) \
$(VENV_DIR)/bin/$(PYTHON_CMD) -m pytest -vv
test-act: ## Run the CI test workflow locally with act
$(ACT_CMD) -W $(ACT_WORKFLOW) -j $(ACT_JOB) --pull=$(ACT_PULL) --container-architecture $(ACT_CONTAINER_ARCH)
.PHONY: usage install install-test install-lint clean publish test test-act lint