name: Build MCP Server
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
push:
paths:
- "server/**"
- ".github/workflows/build-server.yml"
workflow_dispatch:
permissions:
contents: read
packages: write
pull-requests: write
actions: write
jobs:
test:
name: Pytest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: server
load: true
build-args: |
BUILD_ENV=dev
tags: mcp-server:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests and output results
run: |
set -o pipefail
docker run --rm -e BUILD_ENV=dev mcp-server:test | tee pytest_output.txt
exit_code=${PIPESTATUS[0]}
echo '```' >> "$GITHUB_STEP_SUMMARY"
cat pytest_output.txt >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
exit $exit_code
build:
name: Docker build
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
context: workflow
images: |
name=ghcr.io/${{ github.repository }}/server
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha,enable={{is_default_branch}},prefix=${{ github.event_name == 'pull_request' && 'pr-' || github.ref_name }}-
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push production image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: server
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_ENV=prod
cache-from: type=gha
cache-to: type=gha,mode=max