-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·187 lines (161 loc) · 5.69 KB
/
run.sh
File metadata and controls
executable file
·187 lines (161 loc) · 5.69 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
#!/bin/bash
#
# dbt-feldera dev/test script. Requires Python 3.10+, uv, Docker (for integration/e2e).
#
# Usage: .scripts/run.sh <target>
#
# Targets: venv | build | lint | unit-test | integration-test | e2e | all
#
# Each target is idempotent — auto-creates the venv if missing.
# Set FELDERA_SKIP_DOCKER=1 / FELDERA_URL to control Docker behavior.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
VENV_DIR="${PROJECT_DIR}/.venv"
DOCKER_COMPOSE_FILE="${PROJECT_DIR}/integration_tests/docker-compose.yml"
DOCKER_PROJECT="feldera-dbt-test"
export DBT_THREADS="${DBT_THREADS:-4}"
declare -A TARGETS=(
["venv"]="Fresh venv + install deps"
["build"]="Build wheel to dist/"
["fix"]="ruff auto-fix + format"
["lint"]="ruff check + format"
["unit-test"]="pytest unit tests"
["seed-ci"]="Download seed data from GitHub Gist"
["integration-test"]="pytest integration with Feldera in Docker"
["e2e"]="dbt CLI end-to-end with Feldera in Docker"
["all"]="Run all targets in sequence"
)
TARGET_ORDER=("venv" "build" "fix" "lint" "unit-test" "seed-ci" "integration-test" "e2e")
print_usage() {
echo
printf " %-20s %s\n" "TARGET" "DESCRIPTION"
printf " %-20s %s\n" "all" "${TARGETS[all]}"
for t in "${TARGET_ORDER[@]}"; do printf " %-20s %s\n" "$t" "${TARGETS[$t]}"; done
echo
echo "Usage: .scripts/run.sh <target>"
echo
}
TARGET="${1:-}"
if [[ -z "$TARGET" ]]; then echo "ERROR: No target provided."; print_usage; exit 1; fi
if [[ "$TARGET" != "all" && -z "${TARGETS[$TARGET]:-}" ]]; then echo "ERROR: Unknown target '$TARGET'"; print_usage; exit 1; fi
activate_venv() {
# shellcheck disable=SC1091
source "${VENV_DIR}/bin/activate"
}
create_venv() {
rm -rf "${VENV_DIR}"
cd "${PROJECT_DIR}"
uv venv "${VENV_DIR}"
activate_venv
uv sync --all-extras
}
ensure_venv() {
if [[ ! -d "${VENV_DIR}" ]]; then create_venv; else activate_venv; fi
}
run_venv() { create_venv; }
run_build() { ensure_venv; cd "${PROJECT_DIR}"; rm -rf dist/; uv build --wheel 2>&1 | tail -5; echo " Built: $(ls dist/*.whl)"; }
run_fix() { ensure_venv; cd "${PROJECT_DIR}"; uv run ruff check --fix dbt/ tests/ integration_tests/; uv run ruff format dbt/ tests/ integration_tests/; }
run_lint() { ensure_venv; cd "${PROJECT_DIR}"; uv run ruff check dbt/ tests/ integration_tests/; uv run ruff format --check dbt/ tests/ integration_tests/; }
run_unit_test() { ensure_venv; cd "${PROJECT_DIR}"; uv run pytest tests/ -vv; }
run_seed_ci() {
ensure_venv
cd "${PROJECT_DIR}"
echo "Downloading seed data from GitHub Gist..."
uv run python integration_tests/scripts/download_seeds.py integration_tests/dbt-adventureworks
}
start_feldera() {
docker compose -f "${DOCKER_COMPOSE_FILE}" \
-p "${DOCKER_PROJECT}" up -d --wait --wait-timeout 300
}
resolve_feldera_url() {
local base="${FELDERA_URL:-http://localhost:8080}"
if curl -sf --connect-timeout 3 "${base}/healthz" >/dev/null 2>&1; then
echo "$base"
return
fi
if [[ "$base" == *localhost* || "$base" == *127.0.0.1* ]]; then
local alt="${base//localhost/host.docker.internal}"
alt="${alt//127.0.0.1/host.docker.internal}"
if curl -sf --connect-timeout 3 "${alt}/healthz" >/dev/null 2>&1; then
echo "$alt"
return
fi
fi
echo "$base"
}
wait_for_feldera() {
local base="${FELDERA_URL:-http://localhost:8080}"
local alt=""
if [[ "$base" == *localhost* || "$base" == *127.0.0.1* ]]; then
alt="${base//localhost/host.docker.internal}"
alt="${alt//127.0.0.1/host.docker.internal}"
fi
for i in $(seq 1 60); do
if curl -sf --connect-timeout 3 "${base}/healthz" >/dev/null 2>&1; then
export FELDERA_URL="$base"
echo "Feldera is healthy at ${base}"
return 0
fi
if [[ -n "$alt" ]] && curl -sf --connect-timeout 3 "${alt}/healthz" >/dev/null 2>&1; then
export FELDERA_URL="$alt"
echo "Feldera is healthy at ${alt} (Docker-in-Docker fallback)"
return 0
fi
echo "Waiting for Feldera... ($i/60)"
sleep 5
done
echo "ERROR: Feldera did not become healthy in time"
return 1
}
feldera_logs() {
docker compose -f "${DOCKER_COMPOSE_FILE}" \
-p "${DOCKER_PROJECT}" logs --tail=200
}
stop_feldera() {
docker compose -f "${DOCKER_COMPOSE_FILE}" \
-p "${DOCKER_PROJECT}" down -v --remove-orphans
}
run_integration_test() {
ensure_venv
cd "${PROJECT_DIR}"
run_seed_ci
local skip_docker="${FELDERA_SKIP_DOCKER:-}"
if [[ -z "$skip_docker" ]]; then
echo "Starting Feldera via Docker..."
start_feldera
wait_for_feldera
else
export FELDERA_URL="$(resolve_feldera_url)"
fi
echo "Using FELDERA_URL=${FELDERA_URL}"
local rc=0
uv run pytest integration_tests/test_dbt_feldera.py -vv --timeout=600 -m integration || rc=$?
if [[ -z "$skip_docker" ]]; then
if [[ $rc -ne 0 ]]; then
echo ""; echo "── Feldera logs (last 200 lines) ──"
feldera_logs || true
fi
echo "Stopping Feldera..."
stop_feldera || true
fi
return $rc
}
run_e2e() {
ensure_venv
cd "${PROJECT_DIR}"
run_seed_ci
bash integration_tests/scripts/run-dbt-local.sh
}
echo "=== dbt-feldera: ${TARGET} ==="
case "$TARGET" in
"all")
for t in "${TARGET_ORDER[@]}"; do
echo ""; echo "── ${t} ──"
"run_${t//-/_}"
done
echo ""; echo "=== All targets completed. ==="
;;
*) "run_${TARGET//-/_}" ;;
esac