name: CI/CD Pipeline
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
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 }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov flake8 types-requests
- name: Lint with flake8
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics
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: "3.11"
- name: Install security tools
run: |
python -m pip install --upgrade pip
pip install bandit safety
- name: Run Bandit security scan
run: |
bandit -r . -f json -o bandit-report.json --exit-zero
- name: Run Safety check
run: |
safety check --save-json safety-report.json || true
- name: Upload security reports
uses: actions/upload-artifact@v4
with:
name: security-reports
path: |
bandit-report.json
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 zap-custom-mcp:test .
echo "✅ Docker image built successfully"
docker images zap-custom-mcp:test
zap-integration:
name: ZAP Integration Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Download and setup ZAP
run: |
wget https://github.com/zaproxy/zaproxy/releases/download/v2.16.1/ZAP_2.16.1_Linux.tar.gz
tar -xzf ZAP_2.16.1_Linux.tar.gz
sudo mv ZAP_2.16.1 /opt/zap
sudo chmod +x /opt/zap/zap.sh
echo "/opt/zap" >> $GITHUB_PATH
- name: Start ZAP in daemon mode
run: |
/opt/zap/zap.sh -daemon -port 8080 -config api.disablekey=true &
sleep 30
- name: Test MCP server startup
run: |
timeout 120 python -m zap_custom_mcp &
sleep 90
curl -s http://localhost:8082/mcp | head -n 1
notify:
name: Notify on Failure
runs-on: ubuntu-latest
needs: [test, security, docker, zap-integration]
if: failure()
steps:
- name: Notify failure
run: |
echo "CI/CD Pipeline failed. Check the logs for details."