-
Notifications
You must be signed in to change notification settings - Fork 1
74 lines (65 loc) · 2.81 KB
/
tests.yml
File metadata and controls
74 lines (65 loc) · 2.81 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
name: Tests
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev, staging, main ]
jobs:
unit-integration:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: metrics_db
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres -d metrics_db"
--health-interval=5s
--health-timeout=5s
--health-retries=12
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install project and test deps
run: |
pip install -U pip
pip install -e .
pip install pytest "sqlalchemy>=2" psycopg2-binary pandas requests
- name: Wait for Postgres
run: |
python - <<'PY'
import time, psycopg2
for i in range(30):
try:
psycopg2.connect(host="localhost", port=5432, user="postgres", password="postgres", dbname="metrics_db").close()
print("Postgres ready"); break
except Exception as e:
print("Waiting...", e); time.sleep(2)
else:
raise SystemExit("Postgres not ready")
PY
- name: Initialize schema (SQLAlchemy)
run: |
python - <<'PY'
from sqlalchemy import create_engine, text
ddl = """
CREATE TABLE IF NOT EXISTS dim_instance (instance_id SERIAL PRIMARY KEY, instance_name TEXT UNIQUE NOT NULL);
CREATE TABLE IF NOT EXISTS dim_metric (metric_id SERIAL PRIMARY KEY, metric_name TEXT UNIQUE NOT NULL, original_unit TEXT);
CREATE TABLE IF NOT EXISTS dim_component (component_id SERIAL PRIMARY KEY, component_name TEXT NOT NULL, component_type TEXT NOT NULL, UNIQUE (component_name, component_type));
CREATE TABLE IF NOT EXISTS dim_date (date_id SERIAL PRIMARY KEY, timestamp_utc TIMESTAMPTZ UNIQUE NOT NULL, year INT, month INT, day INT, hour INT, minute INT, second INT);
CREATE TABLE IF NOT EXISTS fact_metrics (fact_id SERIAL PRIMARY KEY, date_id INT REFERENCES dim_date(date_id), instance_id INT REFERENCES dim_instance(instance_id), metric_id INT REFERENCES dim_metric(metric_id), component_id INT REFERENCES dim_component(component_id), value DOUBLE PRECISION, UNIQUE (date_id, instance_id, metric_id, component_id));
"""
eng = create_engine("postgresql+psycopg2://postgres:postgres@localhost:5432/metrics_db")
with eng.begin() as c:
for stmt in [s.strip() for s in ddl.split(';') if s.strip()]:
c.execute(text(stmt))
print("Schema ready")
PY
- name: Run tests
run: pytest -q