-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
140 lines (112 loc) · 4.29 KB
/
Copy pathmakefile
File metadata and controls
140 lines (112 loc) · 4.29 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
.EXPORT_ALL_VARIABLES:
.ONESHELL:
.SILENT:
SHELL := /bin/bash
.SHELLFLAGS := -euo pipefail -c
MAKEFLAGS += --no-builtin-rules --no-builtin-variables
export PATH := $(abspath .venv)/bin:/opt/homebrew/opt/postgresql@18/bin:$(PATH)
DATA_DIR := $(HOME)/.mailpilot
DOCUMENTS_DIR := $(HOME)/Documents/MailPilot
default: .venv help
check: lint py-test ## Run lint and tests
lint: py-format py-lint py-types ## Lint Python code
py-test: ## Run tests
uv run pytest -x
py-types:
$(call header,Running basedpyright typecheck)
uv run basedpyright
py-format:
$(call header,Running Ruff format)
uv run ruff format
py-lint:
$(call header,Running Ruff lint)
uv run ruff check --fix
db-backup: ## Back up tags, companies and contacts to ~/Documents/MailPilot/ (timestamped JSON snapshot)
$(eval TS := $(shell date +%Y%m%d-%H%M%S))
$(call header,Backing up the database snapshot to $(DOCUMENTS_DIR))
mkdir -p $(DOCUMENTS_DIR)
mailpilot db export --file $(DOCUMENTS_DIR)/snap-$(TS).json > /dev/null
kill-run: ## Force-kill runaway mailpilot run processes (SIGTERM then SIGKILL)
$(call header,Force-killing mailpilot run processes)
pids=$$(pgrep -f 'mailpilot run' 2>/dev/null || true)
if [[ -n "$$pids" ]]; then
echo "Sending SIGTERM to pid(s): $$pids"
kill -TERM $$pids 2>/dev/null || true
sleep 1
still=$$(pgrep -f 'mailpilot run' 2>/dev/null || true)
if [[ -n "$$still" ]]; then
echo "Sending SIGKILL to pid(s): $$still"
kill -KILL $$still 2>/dev/null || true
fi
echo "$(green)mailpilot run processes cleared$(reset)"
else
echo "No mailpilot run processes found"
fi
clean: kill-run db-backup ## Kill runaway run processes, back up data, re-create database
$(call header,Re-creating database)
dropdb --if-exists mailpilot
createdb mailpilot
dropdb --if-exists mailpilot_test
createdb mailpilot_test
mailpilot status
py-update:
uv venv --clear && hash -r && uv sync --upgrade
py-reset:
rm -rf build/ dist/ *.egg-info
find . -type d -name "__pycache__" -exec rm -rf {} +
uv venv --clear && hash -r && uv sync --quiet
.venv: uv.lock
uv venv --clear && hash -r && uv sync
uv.lock: pyproject.toml
uv lock --upgrade && touch $(@)
.gitignore:
cat << EOF > $(@)
**/__pycache__/
.venv/
.env
EOF
config-backup:
gpg -er E4AFCA7FBB19FC029D519A524AEBB5178D5E96C1 -o config.json.gpg ~/.mailpilot/config.json
env-backup:
gpg --yes -er E4AFCA7FBB19FC029D519A524AEBB5178D5E96C1 -o .env.gpg .env
###############################################################################
# Release
###############################################################################
install: ## Install mailpilot globally as an editable uv tool
$(call header,Installing mailpilot via uv tool)
uv tool install --editable .
# `make release <part>` passes the part as an extra goal; pick it out and
# give the part words no-op recipes so make does not try to build them.
part := $(word 1,$(filter major minor patch,$(MAKECMDGOALS)))
release: check ## Bump version, commit, tag, and push; GitHub Actions runs check then publishes GH release + PyPI (make release major|minor|patch)
test -n "$(part)" || { echo "usage: make release major|minor|patch"; exit 1; }
git diff --quiet && git diff --cached --quiet \
|| { echo "working tree not clean — commit or stash first"; exit 1; }
$(call header,Bumping $(part) version)
uv version --bump $(part)
version=$$(uv version --short)
git add pyproject.toml uv.lock
git commit -m "chore: release v$$version"
git tag "v$$version"
$(call header,Pushing v$$version tag (CI will check, then publish GH release + PyPI))
git push && git push --tags
echo "$(green)Tagged v$$version — GitHub Actions runs make check, then publishes release + PyPI$(reset)"
major minor patch:
@:
###############################################################################
# Colors and Headers
###############################################################################
TERM := xterm-256color
blue := $$(tput setaf 4)
green := $$(tput setaf 2)
yellow := $$(tput setaf 3)
reset := $$(tput sgr0)
define header
echo "$(blue)==> $(1) <==$(reset)"
endef
help:
echo "$(blue)Usage: $(green)make [recipe]$(reset)"
echo "$(blue)Recipes:$(reset)"
awk 'BEGIN {FS = ":.*?## "; sort_cmd = "sort"} /^[a-zA-Z0-9_-]+:.*?## / \
{ printf " \033[33m%-10s\033[0m %s\n", $$1, $$2 | sort_cmd; } \
END {close(sort_cmd)}' $(MAKEFILE_LIST)