name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
schedule:
# Run security scans daily
- cron: '0 0 * * *'
env:
GO_VERSION: '1.23'
DOCKER_BUILDKIT: 1
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.23', '1.24']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true
- name: Download dependencies
run: go mod download
- name: Run tests
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
if: matrix.go == '1.23'
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
- name: Run Trivy vulnerability scanner (repo)
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
continue-on-error: true
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
if: success() || failure()
continue-on-error: true
build:
name: Build
runs-on: ubuntu-latest
needs: [test, lint]
strategy:
matrix:
include:
- os: linux
arch: amd64
- os: linux
arch: arm64
- os: darwin
arch: amd64
- os: darwin
arch: arm64
- os: windows
arch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build binary
run: |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build \
-ldflags="-w -s -X main.Version=${{ github.sha }}" \
-o dist/ksm-mcp-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }} \
./cmd/ksm-mcp
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ksm-mcp-${{ matrix.os }}-${{ matrix.arch }}
path: dist/ksm-mcp-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}
docker:
name: Docker Build and Test
runs-on: ubuntu-latest
needs: [test, lint]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image (amd64)
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: false
load: true
tags: ksm-mcp:ci-test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ksm-mcp:ci-test
format: 'sarif'
output: 'trivy-results.sarif'
continue-on-error: true
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
if: always()
continue-on-error: true
- name: Save Docker image
run: |
docker save ksm-mcp:ci-test -o /tmp/ksm-mcp-image.tar
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: docker-image
path: /tmp/ksm-mcp-image.tar
retention-days: 1
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: docker
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp
- name: Load Docker image
run: |
docker load -i /tmp/ksm-mcp-image.tar
docker tag ksm-mcp:ci-test ksm-mcp:latest
- name: Run integration tests
run: |
# Start the container
docker run -d --name ksm-mcp-test \
-e KSM_MCP_LOG_LEVEL=debug \
-e KSM_MCP_BATCH_MODE=true \
ksm-mcp:latest serve
# Wait for container to be ready
sleep 5
# Run integration tests
docker exec ksm-mcp-test ksm-mcp test --run-tests --mode integration || true
# Cleanup
docker stop ksm-mcp-test
docker rm ksm-mcp-test
e2e-test:
name: E2E Tests
runs-on: ubuntu-latest
needs: docker
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: docker-image
path: /tmp
- name: Load Docker image
run: |
docker load -i /tmp/ksm-mcp-image.tar
docker tag ksm-mcp:ci-test ksm-mcp:latest
- name: Run E2E tests
run: |
# Start services using docker compose (v2) with CI config
docker compose -f docker-compose.ci.yml up -d
# Wait for services to be ready
sleep 10
# Check if service is running
docker compose -f docker-compose.ci.yml ps
# Run E2E tests
docker compose -f docker-compose.ci.yml exec -T ksm-mcp ksm-mcp test --run-tests --mode e2e || true
# Show logs if tests fail
docker compose -f docker-compose.ci.yml logs
- name: Collect logs
if: always()
run: |
docker compose -f docker-compose.ci.yml logs > docker-compose.log || true
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-logs
path: docker-compose.log
- name: Cleanup
if: always()
run: |
docker compose -f docker-compose.ci.yml down -v || true