mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
fix(tests): fixed testing DB deployment v5
This commit is contained in:
20
.github/workflows/deploy-pr.yaml
vendored
20
.github/workflows/deploy-pr.yaml
vendored
@@ -12,25 +12,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Run Python Tests
|
name: Run Python Tests
|
||||||
if: github.event.action != 'closed'
|
if: github.event.action != 'closed'
|
||||||
runs-on: ubuntu-latest
|
uses: ./.github/workflows/run-tests.yml
|
||||||
|
|
||||||
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: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
- name: Run tests with pytest
|
|
||||||
run: pytest
|
|
||||||
working-directory: ./7project/backend
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
if: github.event.action != 'closed'
|
if: github.event.action != 'closed'
|
||||||
|
|||||||
21
.github/workflows/deploy-prod.yaml
vendored
21
.github/workflows/deploy-prod.yaml
vendored
@@ -23,26 +23,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Run Python Tests
|
name: Run Python Tests
|
||||||
if: github.event.action != 'closed'
|
uses: ./.github/workflows/run-tests.yml
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
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: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
- name: Run tests with pytest
|
|
||||||
run: pytest
|
|
||||||
working-directory: ./7project/backend
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build and push image (reusable)
|
name: Build and push image (reusable)
|
||||||
|
|||||||
54
.github/workflows/run-tests.yml
vendored
54
.github/workflows/run-tests.yml
vendored
@@ -2,48 +2,31 @@ name: Run Python Tests
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# --- Triggers ----
|
|
||||||
# -----------------
|
|
||||||
# This section defines when the workflow will run.
|
|
||||||
on:
|
on:
|
||||||
# Run on every push to the 'main' branch
|
workflow_call:
|
||||||
push:
|
|
||||||
branches: [ "main" ]
|
|
||||||
# Also run on every pull request that targets the 'main' branch
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# ------ Jobs -----
|
|
||||||
# -----------------
|
|
||||||
# A workflow is made up of one or more jobs that can run in parallel or sequentially.
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build-and-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# 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 # Using the DB name your app expects
|
# 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:
|
|
||||||
- 3306:3306
|
|
||||||
# Healthcheck ensures the job only starts when DB is ready
|
|
||||||
options: >-
|
|
||||||
--health-cmd="mysqladmin ping -h 127.0.0.1 -u root -prootpw --silent"
|
|
||||||
--health-interval=5s
|
|
||||||
--health-timeout=2s
|
|
||||||
--health-retries=20
|
|
||||||
|
|
||||||
# This is the job-level 'env' block
|
# 2) Expose DB connection settings to steps
|
||||||
# It will be used by all steps (alembic, pytest, etc.)
|
|
||||||
env:
|
env:
|
||||||
MARIADB_HOST: 127.0.0.1
|
# Use the service label 'mariadb' as the host
|
||||||
MARIADB_PORT: "3306"
|
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_DB: group_project
|
||||||
MARIADB_USER: appuser
|
MARIADB_USER: appuser
|
||||||
MARIADB_PASSWORD: apppass
|
MARIADB_PASSWORD: apppass
|
||||||
@@ -57,26 +40,21 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: '3.11'
|
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
|
- 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 ./7project/backend/requirements.txt
|
||||||
|
|
||||||
# This step will now wait for the healthcheck to pass
|
|
||||||
# and will use the job-level 'env' block
|
|
||||||
- name: Run Alembic migrations
|
- name: Run Alembic migrations
|
||||||
run: |
|
run: |
|
||||||
alembic upgrade head
|
alembic upgrade head
|
||||||
working-directory: ./7project/backend
|
working-directory: ./7project/backend
|
||||||
|
|
||||||
# This step-level 'env' block overrides any local .env
|
|
||||||
# file that your pytest setup might be loading
|
|
||||||
- name: Run tests with pytest
|
- name: Run tests with pytest
|
||||||
env:
|
|
||||||
MARIADB_HOST: 127.0.0.1
|
|
||||||
MARIADB_PORT: "3306"
|
|
||||||
MARIADB_DB: group_project
|
|
||||||
MARIADB_USER: appuser
|
|
||||||
MARIADB_PASSWORD: apppass
|
|
||||||
run: pytest
|
run: pytest
|
||||||
working-directory: ./7project/backend
|
working-directory: ./7project/backend
|
||||||
Reference in New Issue
Block a user