unique db action run
This commit is contained in:
parent
f407285e60
commit
8e138689cf
1 changed files with 31 additions and 6 deletions
37
.github/workflows/backend.yml
vendored
37
.github/workflows/backend.yml
vendored
|
|
@ -15,14 +15,16 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
backend-test:
|
backend-test:
|
||||||
runs-on: [docker]
|
runs-on: [docker]
|
||||||
|
env:
|
||||||
|
UNIQUE_DB: test_db_${{ github.run_id }}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
env:
|
env:
|
||||||
POSTGRES_USER: test
|
POSTGRES_USER: test
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test_db
|
POSTGRES_DB: test_db_${{ github.run_id }}_${{ github.run_attempt }}
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
|
|
@ -39,13 +41,35 @@ jobs:
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
run: |
|
run: |
|
||||||
python --version
|
python --version
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
cd backend
|
cd backend
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install --cache-dir /tmp/pip-cache -r requirements/dev.txt
|
pip install --cache-dir /tmp/pip-cache -r requirements/dev.txt
|
||||||
|
|
||||||
|
- name: Create Unique Test Database
|
||||||
|
env:
|
||||||
|
DATABASE_URL: postgresql://test:test@postgres:5432/postgres
|
||||||
|
run: |
|
||||||
|
# Install postgresql-client if not present in the alpine image to run psql
|
||||||
|
# Or use python to create the db
|
||||||
|
cd backend
|
||||||
|
python -c "
|
||||||
|
import os
|
||||||
|
from sqlalchemy import create_engine, text
|
||||||
|
db_url = os.environ['DATABASE_URL']
|
||||||
|
engine = create_engine(db_url)
|
||||||
|
new_db = os.environ['UNIQUE_DB']
|
||||||
|
# Connect to default 'postgres' db to create the new one
|
||||||
|
with engine.connect() as conn:
|
||||||
|
conn.execute(text('COMMIT')) # Close any open transactions
|
||||||
|
conn.execute(text(f'DROP DATABASE IF EXISTS {new_db}'))
|
||||||
|
conn.execute(text(f'CREATE DATABASE {new_db}'))
|
||||||
|
print(f'Created database: {new_db}')
|
||||||
|
"
|
||||||
|
|
||||||
|
|
||||||
- name: Debug cache
|
- name: Debug cache
|
||||||
run: |
|
run: |
|
||||||
echo "Listing PIP cache files:"
|
echo "Listing PIP cache files:"
|
||||||
|
|
@ -59,8 +83,9 @@ jobs:
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
TEST_DATABASE_URL: postgresql://test:test@postgres:5432/test_db
|
UNIQUE_DB: test_db_${{ github.run_id }}
|
||||||
DATABASE_URL: postgresql://test:test@postgres:5432/test_db
|
TEST_DATABASE_URL: postgresql://test:test@postgres:5432/${{ env.UNIQUE_DB }}
|
||||||
|
DATABASE_URL: postgresql://test:test@postgres:5432/${{ env.UNIQUE_DB }}
|
||||||
SECRET_KEY: test-secret-key
|
SECRET_KEY: test-secret-key
|
||||||
JWT_SECRET_KEY: test-jwt-secret
|
JWT_SECRET_KEY: test-jwt-secret
|
||||||
FLASK_ENV: test
|
FLASK_ENV: test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue