-
Notifications
You must be signed in to change notification settings - Fork 1
171 lines (153 loc) · 5.74 KB
/
feature-to-main.yml
File metadata and controls
171 lines (153 loc) · 5.74 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
name: Feature PR to Main
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: cueapi_test
POSTGRES_USER: runner
POSTGRES_PASSWORD: ""
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U runner -d cueapi_test"
--health-interval 2s
--health-timeout 3s
--health-retries 15
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 2s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7
- name: Checkout cueapi-core
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.7
with:
repository: cueapi/cueapi-core
path: cueapi-core
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.3.0
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -r cueapi-core/requirements.txt
pip install -e .
- name: Initialize test DB schema (model-driven, matches cueapi-core/tests/conftest.py)
working-directory: cueapi-core
env:
DATABASE_URL: postgresql+asyncpg://runner@localhost:5432/cueapi_test
REDIS_URL: redis://localhost:6379
SESSION_SECRET: test-session-secret-32-chars-minimum!!
ENV: test
RESEND_API_KEY: ""
run: |
python <<'PY'
import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
from app.config import settings
from app.database import Base
# Import all models so Base.metadata sees them (mirrors tests/conftest.py).
from app.models import ( # noqa: F401
Alert, Cue, DispatchOutbox, Execution, UsageMonthly, User, Worker, DeviceCode,
Agent, Message, UsageMessagesMonthly,
)
async def _init():
engine = create_async_engine(settings.DATABASE_URL)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
await engine.dispose()
asyncio.run(_init())
print("Schema initialized via Base.metadata.create_all")
PY
- name: Start cueapi-core API in background
working-directory: cueapi-core
env:
DATABASE_URL: postgresql+asyncpg://runner@localhost:5432/cueapi_test
REDIS_URL: redis://localhost:6379
SESSION_SECRET: test-session-secret-32-chars-minimum!!
ENV: test
RESEND_API_KEY: ""
ALLOW_REGISTER: "true"
BASE_URL: http://localhost:8000
run: |
nohup python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 \
> /tmp/uvicorn.log 2>&1 &
echo $! > /tmp/uvicorn.pid
- name: Wait for API health
run: |
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:8000/health > /dev/null; then
echo "API ready after ${i}s"
exit 0
fi
sleep 1
done
echo "API failed to start within 30s"
cat /tmp/uvicorn.log
exit 1
- name: Register test user and capture API key
id: register_user
run: |
EMAIL="ci-sdk-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}@example.com"
RESP=$(curl -sf -X POST http://127.0.0.1:8000/v1/auth/register \
-H "Content-Type: application/json" \
-d "{\"email\":\"${EMAIL}\"}")
KEY=$(printf '%s' "$RESP" | python -c 'import sys,json;print(json.load(sys.stdin)["api_key"])')
if [ -z "$KEY" ]; then
echo "Registration failed; response: $RESP"
exit 1
fi
echo "::add-mask::$KEY"
echo "api_key=$KEY" >> "$GITHUB_OUTPUT"
- name: Run tests
env:
CUEAPI_STAGING_URL: http://127.0.0.1:8000
CUEAPI_STAGING_API_KEY: ${{ steps.register_user.outputs.api_key }}
run: pytest tests/ -v --tb=short
- name: Dump uvicorn log on failure
if: failure()
run: cat /tmp/uvicorn.log || true
auto-merge:
needs: test
runs-on: ubuntu-latest
steps:
- name: Auto-merge PR
run: gh pr merge ${{ github.event.pull_request.number }} --squash --auto
env:
GH_TOKEN: ${{ secrets.GOVIND_GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
notify-merge:
needs: auto-merge
runs-on: ubuntu-latest
steps:
- name: Create merge confirmation cue
run: |
FIRE_AT=$(date -u -d '+2 minutes' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || \
date -u -v+2M '+%Y-%m-%dT%H:%M:%SZ')
curl -s -w "\n%{http_code}" -X POST https://api.cueapi.ai/v1/cues \
-H "Authorization: Bearer ${{ secrets.ARGUS_CUEAPI_KEY }}" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"cueapi-python-merged-${{ github.event.pull_request.number }}\",
\"schedule\": {\"type\": \"once\", \"at\": \"${FIRE_AT}\"},
\"transport\": \"worker\",
\"payload\": {
\"task\": \"test-sdk\",
\"trigger\": \"post-merge\",
\"repo\": \"cueapi/cueapi-python\",
\"pr_number\": \"${{ github.event.pull_request.number }}\",
\"commit_sha\": \"${{ github.event.pull_request.head.sha }}\"
}
}"