-
Notifications
You must be signed in to change notification settings - Fork 74
79 lines (67 loc) · 2.51 KB
/
dashboard_app_ci.yaml
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
name: DashBoard App CI Workflow
on: [push]
jobs:
run_tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dashboard_app
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies for Dashboard App
working-directory: ./apps/dashboard_app
run: |
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
poetry lock --no-update
poetry install
- name: Prepare Environment File
working-directory: ./apps/dashboard_app
run: |
cp .env.dev .env
sed -i 's/DB_HOST=.*/DB_HOST=127.0.0.1/' .env
sed -i 's/DB_PORT=.*/DB_PORT=5432/' .env
sed -i 's/DB_USER=.*/DB_USER=postgres/' .env
sed -i 's/DB_PASSWORD=.*/DB_PASSWORD=postgres/' .env
sed -i 's/DB_NAME=.*/DB_NAME=dashboard_app/' .env
- name: Add DATABASE_URL to Environment
working-directory: ./apps/data_handler
run: cp .env .env.dev
- name: Set DATABASE_URL for Tests
run: echo "DATABASE_URL=postgresql://postgres:[email protected]:5432/dashboard_app" >> $GITHUB_ENV
- name: Wait for Database to be Ready
run: |
for i in {1..30}; do
pg_isready -h 127.0.0.1 -p 5432 -U postgres && break || sleep 2;
done
- name: Verify PostgreSQL Port is Open
run: |
nc -zv 127.0.0.1 5432
- name: Create Test Database If Not Exists
run: |
PGPASSWORD=postgres psql -h 127.0.0.1 -p 5432 -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'dashboard_app'" | grep -q 1 || \
PGPASSWORD=postgres psql -h 127.0.0.1 -p 5432 -U postgres -c "CREATE DATABASE dashboard_app;"
- name: Run Tests for Dashboard_App
working-directory: ./apps/dashboard_app
env:
DATABASE_URL: postgresql://postgres:[email protected]:5432/dashboard_app
run: poetry run pytest