|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, release ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + lint: |
| 17 | + name: Code Style & Linting |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.12' |
| 27 | + |
| 28 | + - name: Create virtual environment |
| 29 | + run: python -m venv venv |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: | |
| 33 | + source venv/bin/activate |
| 34 | + pip install --upgrade pip |
| 35 | + pip install black flake8 |
| 36 | + pip install -e . |
| 37 | +
|
| 38 | + - name: Run Black |
| 39 | + run: | |
| 40 | + source venv/bin/activate |
| 41 | + black --check --diff src/ tests/ |
| 42 | +
|
| 43 | + - name: Run Flake8 |
| 44 | + run: | |
| 45 | + source venv/bin/activate |
| 46 | + flake8 |
| 47 | +
|
| 48 | + actionlint: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Install actionlint |
| 54 | + run: | |
| 55 | + # Download and install actionlint |
| 56 | + bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) |
| 57 | + echo "${PWD}" >> "$GITHUB_PATH" |
| 58 | +
|
| 59 | + - name: Run actionlint |
| 60 | + run: actionlint |
| 61 | + |
| 62 | + test: |
| 63 | + name: Run Tests |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: [lint, actionlint] |
| 66 | + strategy: |
| 67 | + matrix: |
| 68 | + python-version: ['3.10', '3.11', '3.12'] |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Set up Python ${{ matrix.python-version }} |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: ${{ matrix.python-version }} |
| 78 | + |
| 79 | + - name: Create virtual environment |
| 80 | + run: python -m venv venv |
| 81 | + |
| 82 | + - name: Install dependencies |
| 83 | + run: | |
| 84 | + source venv/bin/activate |
| 85 | + pip install --upgrade pip |
| 86 | + pip install -e ".[test]" |
| 87 | +
|
| 88 | + - name: Run unit tests |
| 89 | + run: | |
| 90 | + source venv/bin/activate |
| 91 | + pytest -m unit -v |
| 92 | +
|
| 93 | + - name: Run client tests |
| 94 | + run: | |
| 95 | + source venv/bin/activate |
| 96 | + pytest tests/test_client_no_server.py -v |
| 97 | +
|
| 98 | + - name: Run integration tests |
| 99 | + run: | |
| 100 | + source venv/bin/activate |
| 101 | + pytest -m integration -v |
| 102 | +
|
| 103 | + docker: |
| 104 | + name: Build and Push Docker Image |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: [lint, actionlint, test] |
| 107 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event_name == 'release' |
| 108 | + permissions: |
| 109 | + contents: read |
| 110 | + packages: write |
| 111 | + steps: |
| 112 | + - name: Checkout code |
| 113 | + uses: actions/checkout@v4 |
| 114 | + |
| 115 | + - name: Install Podman |
| 116 | + run: | |
| 117 | + sudo apt update |
| 118 | + sudo apt install -y podman |
| 119 | +
|
| 120 | + - name: Log in to GitHub Container Registry |
| 121 | + run: | |
| 122 | + echo "${{ secrets.GITHUB_TOKEN }}" | podman login ghcr.io -u ${{ github.repository_owner }} --password-stdin |
| 123 | +
|
| 124 | + - name: Get short SHA |
| 125 | + id: slug |
| 126 | + run: echo "SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)" >> "$GITHUB_OUTPUT" |
| 127 | + |
| 128 | + - name: Build and push container image |
| 129 | + run: | |
| 130 | + # Build the image |
| 131 | + podman build -t "ghcr.io/${{ github.repository }}/vtk-mcp:latest" \ |
| 132 | + -t "ghcr.io/${{ github.repository }}/vtk-mcp:${{ github.sha }}" \ |
| 133 | + -t "ghcr.io/${{ github.repository }}/vtk-mcp:${{ steps.slug.outputs.SHORT_SHA }}" \ |
| 134 | + . |
| 135 | +
|
| 136 | + # Push all tags |
| 137 | + podman push "ghcr.io/${{ github.repository }}/vtk-mcp:latest" |
| 138 | + podman push "ghcr.io/${{ github.repository }}/vtk-mcp:${{ github.sha }}" |
| 139 | + podman push "ghcr.io/${{ github.repository }}/vtk-mcp:${{ steps.slug.outputs.SHORT_SHA }}" |
| 140 | +
|
| 141 | + security: |
| 142 | + name: Security Scan |
| 143 | + runs-on: ubuntu-latest |
| 144 | + needs: docker |
| 145 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event_name == 'release' |
| 146 | + permissions: |
| 147 | + contents: read |
| 148 | + packages: read |
| 149 | + security-events: write |
| 150 | + |
| 151 | + steps: |
| 152 | + - name: Run Trivy vulnerability scanner |
| 153 | + uses: aquasecurity/trivy-action@master |
| 154 | + with: |
| 155 | + image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 156 | + format: 'sarif' |
| 157 | + output: 'trivy-results.sarif' |
| 158 | + |
| 159 | + - name: Upload Trivy scan results to GitHub Security tab |
| 160 | + uses: github/codeql-action/upload-sarif@v3 |
| 161 | + if: always() |
| 162 | + with: |
| 163 | + sarif_file: 'trivy-results.sarif' |
0 commit comments