Skip to content

Finished log in and sign up for volunteers and participants and linked it with the intake form #12

Finished log in and sign up for volunteers and participants and linked it with the intake form

Finished log in and sign up for volunteers and participants and linked it with the intake form #12

Workflow file for this run

name: Backend CI
on:
push:
branches: [ main, develop ]
paths:
- 'backend/**'
- '.github/workflows/backend-ci.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'backend/**'
- '.github/workflows/backend-ci.yml'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12]
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: testpassword
POSTGRES_USER: testuser
POSTGRES_DB: llsc_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install PDM
run: |
pip install pdm
- name: Cache PDM dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pdm
key: ${{ runner.os }}-pdm-${{ hashFiles('backend/pdm.lock') }}
restore-keys: |
${{ runner.os }}-pdm-
- name: Install dependencies
working-directory: ./backend
run: |
pdm sync --group test --group lint --group dev
- name: Set up environment variables
working-directory: ./backend
run: |
echo "POSTGRES_DATABASE_URL=postgresql://testuser:testpassword@localhost:5432/llsc_test" >> .env
echo "SECRET_KEY=test-secret-key-for-ci" >> .env
echo "ENVIRONMENT=test" >> .env
- name: Run database migrations
working-directory: ./backend
run: |
pdm run alembic upgrade head
- name: Run linting
working-directory: ./backend
run: |
pdm run ruff check .
pdm run ruff format --check .
# TODO: Re-enable mypy when type annotations are improved
# - name: Run type checking
# working-directory: ./backend
# run: |
# pdm run mypy app/ --ignore-missing-imports
- name: Run unit tests
working-directory: ./backend
run: |
pdm run python -m pytest tests/unit/ -v --cov=app --cov-report=xml --cov-report=term-missing
- name: Run integration tests
working-directory: ./backend
run: |
pdm run python -m pytest tests/functional/ -v
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./backend/coverage.xml
directory: ./backend
flags: backend
name: backend-coverage
- name: Run security scan
working-directory: ./backend
run: |
pdm run bandit -r app/ -f json -o security-report.json || true
- name: Upload security report
uses: actions/upload-artifact@v4
if: always()
with:
name: security-report
path: backend/security-report.json
e2e-tests:
runs-on: ubuntu-latest
needs: test
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: testpassword
POSTGRES_USER: testuser
POSTGRES_DB: llsc_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install PDM
run: |
pip install pdm
- name: Install dependencies
working-directory: ./backend
run: |
pdm sync --group test --group lint --group dev
- name: Set up environment variables
working-directory: ./backend
run: |
echo "POSTGRES_DATABASE_URL=postgresql://testuser:testpassword@localhost:5432/llsc_test" >> .env
echo "SECRET_KEY=test-secret-key-for-ci" >> .env
echo "ENVIRONMENT=test" >> .env
echo "TEST_SCRIPT_BACKEND_URL=http://localhost:8000" >> .env
echo "[email protected]" >> .env
echo "TEST_SCRIPT_PASSWORD=testpassword" >> .env
- name: Run database migrations
working-directory: ./backend
run: |
pdm run alembic upgrade head
- name: Start backend server
working-directory: ./backend
run: |
pdm run uvicorn app.server:app --host 0.0.0.0 --port 8000 &
sleep 10 # Wait for server to start
- name: Run E2E tests
working-directory: ./
run: |
pdm run python -m pytest e2e-tests/ -v --tb=short
docker-build:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
working-directory: ./backend
run: |
docker build -t llsc-backend:latest .
- name: Test Docker image
run: |
docker run --rm llsc-backend:latest python --version
notify:
runs-on: ubuntu-latest
needs: [test, e2e-tests]
if: always()
steps:
- name: Notify on success
if: needs.test.result == 'success' && needs.e2e-tests.result == 'success'
run: |
echo "✅ All tests passed! Backend is ready for deployment."
- name: Notify on failure
if: needs.test.result == 'failure' || needs.e2e-tests.result == 'failure'
run: |
echo "❌ Tests failed! Please check the logs."
exit 1