name: Deploy PDP MCP Server to Development
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
env:
PYTHON_VERSION: '3.11'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run linting (optional)
run: |
pip install flake8
flake8 src/ --count --select=E9,F63,F7,F82 --show-source --statistics || true
- name: Run tests
run: |
python -m pytest tests/ -v --tb=short
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
continue-on-error: true # Tests may fail without API keys
deploy:
needs: test
runs-on: ubuntu-latest
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to SSH Server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
# Configuration
DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}"
# Navigate to deployment directory
cd "$DEPLOY_PATH" || exit 1
# Pull latest changes
echo "π₯ Pulling latest changes..."
git fetch origin master
git reset --hard origin/master
# Activate virtual environment
echo "π Activating virtual environment..."
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
source venv/bin/activate
# Install/update dependencies
echo "π¦ Installing dependencies..."
pip install --upgrade pip
pip install -r requirements.txt
# Update environment variables
echo "π§ Updating environment variables..."
cat > .env << EOF
PINECONE_API_KEY=${{ secrets.PINECONE_API_KEY }}
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
PINECONE_INDEX_NAME=pdp-knowledge
GEMINI_EMBEDDING_MODEL=models/text-embedding-004
MCP_SERVER_NAME=UU PDP Assistant
LOG_LEVEL=INFO
EOF
# Restart service
echo "π Restarting service..."
sudo systemctl restart pdp-mcp-server || echo "Service not configured yet"
# Check status
echo "β
Deployment complete!"
sudo systemctl status pdp-mcp-server --no-pager || echo "Service status check skipped"
notify:
needs: [test, deploy]
runs-on: ubuntu-latest
if: always()
steps:
- name: Deployment Status
run: |
if [ "${{ needs.deploy.result }}" == "success" ]; then
echo "β
Deployment successful!"
elif [ "${{ needs.deploy.result }}" == "skipped" ]; then
echo "βοΈ Deployment skipped (not main branch or PR)"
else
echo "β Deployment failed!"
exit 1
fi