fix(tests): fixed testing DB deployment

This commit is contained in:
ribardej
2025-10-29 13:50:04 +01:00
parent cf1d520a30
commit edb4dfd147

View File

@@ -19,69 +19,57 @@ on:
# ----------------- # -----------------
# A workflow is made up of one or more jobs that can run in parallel or sequentially. # A workflow is made up of one or more jobs that can run in parallel or sequentially.
jobs: jobs:
# A descriptive name for your job
build-and-test: build-and-test:
# Specifies the virtual machine to run the job on. 'ubuntu-latest' is a common and cost-effective choice.
runs-on: ubuntu-latest runs-on: ubuntu-latest
# 1) Start a MariaDB service container for tests # 1) Start a MariaDB service container for tests
services: services:
# The label 'mariadb' becomes the hostname
mariadb: mariadb:
image: mariadb:11.4 image: mariadb:11.4
env: env:
MARIADB_ROOT_PASSWORD: rootpw MARIADB_ROOT_PASSWORD: rootpw
MARIADB_DATABASE: group_project_test # This DB name now matches what your app expects
MARIADB_DATABASE: group_project
MARIADB_USER: appuser MARIADB_USER: appuser
MARIADB_PASSWORD: apppass MARIADB_PASSWORD: apppass
ports: # 'ports' and 'options' are removed.
- 3306:3306 # GitHub Actions will use the image's default healthcheck.
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -u root -prootpw --silent"
--health-interval=5s
--health-timeout=2s
--health-retries=20
# 2) Expose DB connection settings to steps so your app picks them up # 2) Expose DB connection settings to steps
env: env:
MARIADB_HOST: 127.0.0.1 # Use the service label 'mariadb' as the host
MARIADB_PORT: "3306" MARIADB_HOST: mariadb
MARIADB_DB: group_project_test MARIADB_PORT: "3306" # This is the internal port, which is correct
# Match the database name from the service
MARIADB_DB: group_project
MARIADB_USER: appuser MARIADB_USER: appuser
MARIADB_PASSWORD: apppass MARIADB_PASSWORD: apppass
# Optional: enable SQL echo logs in CI for debugging
# SQL_ECHO: "1"
# ----------------- # -----------------
# ----- Steps ----- # ----- Steps -----
# ----------------- # -----------------
# A sequence of tasks that will be executed as part of the job.
steps: steps:
# Step 1: Check out your repository's code # ... (your steps remain the same) ...
# This action allows the workflow to access your code.
- name: Check out repository code - name: Check out repository code
uses: actions/checkout@v4 uses: actions/checkout@v4
# Step 2: Set up the Python environment
# This action installs a specific version of Python on the runner.
- name: Set up Python 3.11 - name: Set up Python 3.11
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.11' # Use the Python version that matches your project python-version: '3.11'
# Step 3: Install project dependencies (from repo root)
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r requirements.txt pip install -r requirements.txt
# Step 4: Apply DB migrations before running tests
- name: Run Alembic migrations - name: Run Alembic migrations
run: | run: |
alembic upgrade head alembic upgrade head
working-directory: ./7project/backend working-directory: ./7project/backend
# Step 5: Run your tests!
# Executes the pytest command to run your test suite.
- name: Run tests with pytest - name: Run tests with pytest
run: pytest run: pytest
working-directory: ./7project/backend working-directory: ./7project/backend