name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run tests daily at 2 AM UTC
- cron: '0 2 * * *'
env:
PYTHON_DEFAULT_VERSION: "3.13"
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run unit tests
run: |
python -m pytest tests/unit -v --tb=short --cov=server --cov-report=xml --cov-report=term-missing
env:
PYTHONPATH: ${{ github.workspace }}
- name: Run integration tests
run: |
python -m pytest tests/integration -v --tb=short -m "not slow"
env:
PYTHONPATH: ${{ github.workspace }}
- name: Upload coverage to Codecov
if: matrix.python-version == env.PYTHON_DEFAULT_VERSION && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
lint:
if: false
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run ruff linter
run: |
python -m ruff check . --output-format=github
- name: Run ruff formatter check
run: |
python -m ruff format --check .
- name: Run black formatter check
run: |
python -m black --check --diff .
- name: Run isort import sorting check
run: |
python -m isort --check-only --diff .
- name: Run mypy type checking
run: |
python -m mypy server/
continue-on-error: true # Type checking failures shouldn't block CI
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run bandit security linter
run: |
python -m bandit -r server/ -f json -o bandit-report.json
continue-on-error: true
- name: Upload bandit report
uses: actions/upload-artifact@v4
if: always()
with:
name: bandit-report
path: bandit-report.json
- name: Run safety check
run: |
python -m safety check --json --output safety-report.json
continue-on-error: true
- name: Upload safety report
uses: actions/upload-artifact@v4
if: always()
with:
name: safety-report
path: safety-report.json
docker:
name: Docker Build Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
docker build -t prims:test .
- name: Test Docker image
run: |
# Start container in background
docker run -d --name prims-test -p 9000:9000 prims:test
# Wait for container to start
sleep 10
# Test health endpoint (if available)
curl -f http://localhost:9000/health || echo "Health endpoint not available yet"
# Clean up
docker stop prims-test
docker rm prims-test
integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: [test, lint]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run integration tests
run: |
python -m pytest tests/integration -v --tb=short
env:
PYTHONPATH: ${{ github.workspace }}
- name: Run end-to-end tests
run: |
# Start the server in background
python -m server.main &
SERVER_PID=$!
# Wait for server to start
sleep 5
# Run E2E tests against running server
python -m pytest tests/integration -v -m "e2e" || true
# Clean up
kill $SERVER_PID || true
env:
PYTHONPATH: ${{ github.workspace }}
PORT: 9001
build-and-publish:
name: Build and Publish
runs-on: ubuntu-latest
needs: [test, lint, security, docker, integration]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install build dependencies
run: |
python -m pip install --upgrade pip build twine
- name: Build package
run: |
python -m build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# Uncomment when ready to publish to PyPI
# - name: Publish to PyPI
# if: startsWith(github.ref, 'refs/tags/v')
# env:
# TWINE_USERNAME: __token__
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
# run: |
# python -m twine upload dist/*
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
fail-on-severity: moderate
performance:
name: Performance Tests
runs-on: ubuntu-latest
needs: [test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run performance tests
run: |
python -m pytest tests/performance -v --tb=short || echo "Performance tests not implemented yet"
env:
PYTHONPATH: ${{ github.workspace }}
notify:
name: Notify Results
runs-on: ubuntu-latest
needs: [test, lint, security, docker, integration]
if: always()
steps:
- name: Determine status
id: status
run: |
if [[ "${{ needs.test.result }}" == "success" && "${{ needs.lint.result }}" == "success" ]]; then
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
fi
- name: Create summary
run: |
echo "## CI/CD Pipeline Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Test Suite | ${{ needs.test.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Code Quality | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security Scan | ${{ needs.security.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Docker Build | ${{ needs.docker.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration Tests | ${{ needs.integration.result }} |" >> $GITHUB_STEP_SUMMARY