Modern QA2026Automated Drift Detection in CI — tiles
Log inJoin
80 / 89 · 04 API & Contract Testing with AI · Schema Drift Detection← prev⊞ allnext →☰ Read as one page

12.4Automated Drift Detection in CI

# .github/workflows/schema-drift.yml
name: Schema Drift Detection
on:
  schedule:
    - cron: '0 6 * * *'  # Daily at 6 AM
  push:
    paths:
      - 'docs/openapi.yaml'

jobs:
  detect-drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Start staging environment
        run: docker-compose up -d

      - name: Wait for API
        run: |
          for i in $(seq 1 30); do
            curl -s http://localhost:8080/health && break
            sleep 2
          done

      - name: Run drift detection
        run: |
          python -m schema_drift_detector \
            --spec docs/openapi.yaml \
            --base-url http://localhost:8080 \
            --output drift-report.json

      - name: Fail on high-severity drift
        run: |
          HIGH_COUNT=$(jq '[.drifts[] | select(.severity=="HIGH")] | length' drift-report.json)
          if [ "$HIGH_COUNT" -gt 0 ]; then
            echo "Found $HIGH_COUNT high-severity schema drifts:"
            jq '.drifts[] | select(.severity=="HIGH")' drift-report.json
            exit 1
          fi

      - name: Upload drift report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: schema-drift-report
          path: drift-report.json