-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile
More file actions
executable file
·259 lines (213 loc) · 5.42 KB
/
Taskfile
File metadata and controls
executable file
·259 lines (213 loc) · 5.42 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env bash
set -euo pipefail
UV="${UV:-uv}"
UV_RUN="${UV} run"
PYTEST="${UV_RUN} pytest --import-mode=importlib"
RUFF="${UV_RUN} ruff"
MYPY="${UV_RUN} mypy"
PRE_COMMIT="${UV_RUN} pre-commit"
VERSION_DOCKER="$(git describe --tags --always --dirty=-dev 2>/dev/null || echo latest)"
function task:help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | sed -En 's/^task:(.*)/\1/p' | sed 's/_/-/g' | sort | cat -n
}
function task:default {
task:help
}
function task:install {
${UV} sync --no-dev --group=all
}
function task:dev_install {
${UV} sync --dev
${PRE_COMMIT} install
}
function task:clean {
rm -rf dist build *.egg-info node_modules \
.venv htmlcov .uv-cache .ruff_cache .mypy_cache \
.pytest_cache .direnv
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
rm -f .coverage coverage.xml pnpm-lock.yaml
}
function task:fix_hard {
${RUFF} check . --fix --unsafe-fixes || true
${RUFF} check . --select F401 --fix --unsafe-fixes || true
${RUFF} check . --select I --fix --unsafe-fixes || true
${RUFF} format . || true
}
function task:format {
${RUFF} format .
}
function task:lint_fix {
${RUFF} check . --fix
}
function task:fix {
task:format
task:lint_fix
${RUFF} check . --fix --unsafe-fixes
}
function task:test {
echo "Running all tests with coverage..."
if [[ ! -d tests ]]; then
echo "Error: tests/ directory not found. Create tests/ directory and add test files."
exit 1
fi
${PYTEST} -v --cov=ccproxy --cov-report=term "$@"
}
function task:test_unit {
echo "Running fast unit tests (excluding real API calls and integration tests)..."
${PYTEST} -v -m "not integration" --tb=short "$@"
}
function task:test_integration {
echo "Running integration tests across all plugins..."
local target="tests/"
if [[ $# -gt 0 && "$1" != -* ]]; then
target="$1"
shift
fi
${PYTEST} -v -m "integration and not slow and not real_api" --tb=short -n auto "${target}" "$@"
}
function task:test_plugins {
echo "Running plugin tests under tests/plugins..."
local target="tests/plugins"
if [[ $# -gt 0 && "$1" != -* ]]; then
target="$1"
shift
fi
${PYTEST} -v --tb=short --no-cov "${target}" "$@"
}
function task:test_file {
if [[ $# -lt 1 ]]; then
echo "Usage: $0 test-file <path/to/test_file.py>"
exit 1
fi
local file="$1"
shift
task:check
echo "Running specific test file: ${file}"
${PYTEST} -v "${file}" "$@"
}
function task:test_match {
if [[ $# -lt 1 ]]; then
echo "Usage: $0 test-match <pattern>"
exit 1
fi
local pattern="$1"
shift
task:check
echo "Running tests matching pattern: ${pattern}"
${PYTEST} -v -k "${pattern}" "$@"
}
function task:typecheck {
${MYPY} .
}
function task:lint {
${RUFF} check .
}
function task:format_check {
${RUFF} format --check .
}
function task:check_boundaries {
${UV_RUN} python scripts/check_import_boundaries.py
}
function task:check {
task:lint
task:typecheck
task:format_check
task:check_boundaries
}
function task:test_coverage {
task:check
echo "Running tests with detailed coverage report..."
${PYTEST} -v --cov=ccproxy --cov-report=term-missing --cov-report=html -m "not slow and not real_api" "$@"
echo "HTML coverage report generated in htmlcov/"
}
function task:pre_commit {
${PRE_COMMIT} run --all-files
}
function task:ci {
task:pre_commit
task:test
}
function task:build {
${UV} build
}
function task:build_backend {
task:build
}
function task:build_dashboard {
make -C dashboard build
}
function task:dashboard {
echo "Dashboard commands:"
echo "Use 'make -C dashboard <target>' to run dashboard commands"
echo "Available dashboard targets:"
make -C dashboard help
}
function task:docker_build {
docker build -t "ghcr.io/caddyglow/ccproxy:${VERSION_DOCKER}" .
}
function task:docker_run {
docker run --rm -p 8000:8000 "ghcr.io/caddyglow/ccproxy:${VERSION_DOCKER}"
}
function task:docker_compose_up {
docker-compose up --build
}
function task:docker_compose_down {
docker-compose down
}
function task:dev {
LOGGING__LEVEL=trace \
LOGGING__FILE=/tmp/ccproxy/ccproxy.log \
LOGGING__VERBOSE_API=true \
LOGGING__PLUGIN_LOG_BASE_DIR=/tmp/ccproxy \
PLUGINS__REQUEST_TRACER__ENABLED=true \
PLUGINS__ACCESS_LOG__ENABLED=true \
PLUGINS__ACCESS_LOG__CLIENT_LOG_FILE=/tmp/ccproxy/combined_access.log \
PLUGINS__ACCESS_LOG__CLIENT_FORMAT=combined \
HTTP__COMPRESSION_ENABLED=false \
SERVER__RELOAD=true \
SERVER__WORKERS=1 \
${UV_RUN} ccproxy-api serve
}
function task:prod {
${UV_RUN} ccproxy serve
}
function task:docs_install {
${UV} sync --all-groups
}
function task:docs_build {
task:docs_install
${UV_RUN} mkdocs build
}
function task:docs_serve {
task:docs_install
${UV_RUN} mkdocs serve
}
function task:docs_clean {
rm -rf site docs/.cache
}
function task:docs_deploy {
task:docs_build
echo "Documentation built and ready for deployment"
echo "Upload the 'site/' directory to your web server"
}
function task:setup {
task:dev_install
echo "Development environment ready!"
echo "Run './Taskfile dev' to start the server"
}
TIMEFORMAT="Task completed in %3lR"
function __task_dispatch {
local task_name="${1:-default}"
shift || true
local task_func="task:${task_name//-/_}"
if ! declare -F "${task_func}" >/dev/null; then
echo "Unknown task: ${task_name}"
task:help
exit 1
fi
time "${task_func}" "$@"
}
__task_dispatch "$@"