mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
70 lines
2.0 KiB
YAML
70 lines
2.0 KiB
YAML
name: Run Python Tests
|
|
permissions:
|
|
contents: read
|
|
|
|
# -----------------
|
|
# --- Triggers ----
|
|
# -----------------
|
|
# This section defines when the workflow will run.
|
|
on:
|
|
workflow_call:
|
|
|
|
# -----------------
|
|
# ------ Jobs -----
|
|
# -----------------
|
|
# A workflow is made up of one or more jobs that can run in parallel or sequentially.
|
|
jobs:
|
|
# A descriptive name for your job
|
|
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
|
|
|
|
# 1) Start a MariaDB service container for tests
|
|
services:
|
|
# The label 'mariadb' becomes the hostname
|
|
mariadb:
|
|
image: mariadb:11.4
|
|
env:
|
|
MARIADB_ROOT_PASSWORD: rootpw
|
|
# This DB name now matches what your app expects
|
|
MARIADB_DATABASE: group_project
|
|
MARIADB_USER: appuser
|
|
MARIADB_PASSWORD: apppass
|
|
|
|
# 2) Expose DB connection settings to steps
|
|
env:
|
|
# Use the service label 'mariadb' as the host
|
|
MARIADB_HOST: mariadb
|
|
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_PASSWORD: apppass
|
|
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python 3.11
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Add test dependencies to requirements
|
|
run: |
|
|
echo "pytest==8.4.2" >> ./7project/backend/requirements.txt
|
|
echo "pytest-asyncio==1.2.0" >> ./7project/backend/requirements.txt
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r ./7project/backend/requirements.txt
|
|
|
|
- name: Run Alembic migrations
|
|
run: |
|
|
alembic upgrade head
|
|
working-directory: ./7project/backend
|
|
|
|
- name: Run tests with pytest
|
|
run: pytest
|
|
working-directory: ./7project/backend |