# Kepler MCP Server Template - CI Pipeline
#
# This workflow runs on:
# - All pull requests to main
# - All pushes to main
# - Manual workflow dispatch
#
# Jobs:
# 1. lint: Build lint stage and run all quality checks
# 2. test: Run pytest in the lint container
# 3. build: Build the production runtime image
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# ==========================================================================
# Lint Stage - Quality checks via Docker
# ==========================================================================
lint:
name: Lint & Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build lint stage
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: lint
tags: kepler-mcp-gitlab:lint
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Verify lint stage completed
run: |
echo "Lint stage build completed successfully"
echo "All quality checks (ruff, mypy, bandit, safety) passed"
# ==========================================================================
# Test Stage - Run pytest
# ==========================================================================
test:
name: Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build lint stage for testing
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: lint
tags: kepler-mcp-gitlab:lint
load: true
cache-from: type=gha
- name: Run tests with coverage
run: |
docker run --rm kepler-mcp-gitlab:lint \
pytest --cov=src/kepler_mcp_gitlab --cov-report=xml --cov-report=term tests/
- name: Upload coverage report
uses: codecov/codecov-action@v3
if: github.event_name != 'pull_request'
with:
files: ./coverage.xml
fail_ci_if_error: false
# ==========================================================================
# Build Stage - Production image
# ==========================================================================
build:
name: Build Runtime Image
runs-on: ubuntu-latest
needs: [lint, test]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build runtime image
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
target: runtime
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Output image info
run: |
echo "Image built successfully"
echo "Tags: ${{ steps.meta.outputs.tags }}"