-
Notifications
You must be signed in to change notification settings - Fork 59
CI Integration
geoffrey fernald edited this page Jan 26, 2026
·
1 revision
Integrate Drift into your CI/CD pipeline for automated pattern drift detection.
Add Drift to your CI pipeline in 3 steps:
# 1. Install
npm install -g driftdetect
# 2. Initialize (if not already)
drift init --yes
# 3. Run quality gate
drift gate --ci --fail-on errorname: Drift Pattern Check
on:
pull_request:
branches: [main, develop]
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Drift
run: npm install -g driftdetect
- name: Initialize Drift
run: drift init --yes
- name: Scan for patterns
run: drift scan
- name: Run quality gate
run: drift gate --ci --format githubCache the .drift folder to speed up subsequent runs:
name: Drift Pattern Check
on:
pull_request:
branches: [main, develop]
push:
branches: [main]
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Cache Drift data
uses: actions/cache@v4
with:
path: .drift
key: drift-${{ runner.os }}-${{ hashFiles('**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx', '**/*.py') }}
restore-keys: |
drift-${{ runner.os }}-
- name: Install Drift
run: npm install -g driftdetect
- name: Initialize Drift
run: drift init --yes
- name: Incremental scan
run: drift scan --incremental
- name: Run quality gate
run: drift gate --ci --format githubname: Drift Full Pipeline
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
drift-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Cache Drift data
uses: actions/cache@v4
with:
path: .drift
key: drift-${{ runner.os }}-${{ github.sha }}
restore-keys: |
drift-${{ runner.os }}-
- name: Install Drift
run: npm install -g driftdetect
- name: Initialize Drift
run: drift init --yes
- name: Full scan
run: drift scan --verbose
- name: Run quality gate
id: gate
run: drift gate --ci --format sarif --output drift-results.sarif
continue-on-error: true
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: drift-results.sarif
- name: Upload Drift artifacts
uses: actions/upload-artifact@v4
with:
name: drift-analysis
path: |
.drift/patterns/
.drift/views/
drift-results.sarif
retention-days: 30
- name: Check gate result
if: steps.gate.outcome == 'failure'
run: exit 1For monorepos, scan each package separately:
name: Drift Monorepo Check
on:
pull_request:
branches: [main]
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.changes.outputs.packages }}
steps:
- uses: actions/checkout@v4
- id: changes
uses: dorny/paths-filter@v3
with:
filters: |
backend:
- 'packages/backend/**'
frontend:
- 'packages/frontend/**'
shared:
- 'packages/shared/**'
drift-check:
needs: detect-changes
runs-on: ubuntu-latest
strategy:
matrix:
package: [backend, frontend, shared]
if: needs.detect-changes.outputs.packages != '[]'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Drift
run: npm install -g driftdetect
- name: Scan package
run: |
cd packages/${{ matrix.package }}
drift init --yes
drift scan
drift gate --ci --format github# .gitlab-ci.yml
drift:
image: node:20
stage: test
script:
- npm install -g driftdetect
- drift init --yes
- drift scan
- drift gate --ci --format gitlab
artifacts:
reports:
codequality: drift-report.json
paths:
- .drift/
expire_in: 1 week
cache:
key: drift-${CI_COMMIT_REF_SLUG}
paths:
- .drift/drift:
image: node:20
stage: test
script:
- npm install -g driftdetect
- drift init --yes
- drift scan --incremental
- drift gate --ci --format gitlab --output drift-report.json
artifacts:
reports:
codequality: drift-report.json
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"# azure-pipelines.yml
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '20.x'
- script: npm install -g driftdetect
displayName: 'Install Drift'
- script: drift init --yes
displayName: 'Initialize Drift'
- script: drift scan
displayName: 'Scan codebase'
- script: drift gate --ci --format json --output $(Build.ArtifactStagingDirectory)/drift-results.json
displayName: 'Run quality gate'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drift-results'# .circleci/config.yml
version: 2.1
jobs:
drift-check:
docker:
- image: cimg/node:20.0
steps:
- checkout
- restore_cache:
keys:
- drift-{{ checksum "package.json" }}
- drift-
- run:
name: Install Drift
command: npm install -g driftdetect
- run:
name: Initialize and Scan
command: |
drift init --yes
drift scan --incremental
- run:
name: Quality Gate
command: drift gate --ci --format json --output drift-results.json
- save_cache:
key: drift-{{ checksum "package.json" }}
paths:
- .drift
- store_artifacts:
path: drift-results.json
workflows:
main:
jobs:
- drift-checkCreates inline annotations on PR diffs:
::error file=src/api/users.ts,line=42::Pattern violation: Missing error handling
::warning file=src/utils/auth.ts,line=15::New outlier detected in auth-middleware pattern
Generates GitLab Code Quality report:
[
{
"description": "Pattern violation: Missing error handling",
"fingerprint": "abc123",
"severity": "major",
"location": {
"path": "src/api/users.ts",
"lines": { "begin": 42 }
}
}
]Standard format for security/quality tools:
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [...]
}Raw JSON for custom processing:
{
"passed": false,
"score": 72,
"violations": [...],
"gates": {...}
}The .drift folder contains learned patterns and call graph data. Caching it:
- Speeds up incremental scans by 10-50x
- Preserves pattern history for regression detection
- Reduces CI minutes
drift scan --incrementalOnly scans files that changed since last scan, dramatically faster for large codebases.
- name: Full scan on main
if: github.ref == 'refs/heads/main'
run: drift scan --force
- name: Incremental scan on PR
if: github.event_name == 'pull_request'
run: drift scan --incrementaldrift gate --fail-on error # Only fail on errors
drift gate --fail-on warning # Fail on warnings too
drift gate --fail-on none # Never fail (report only)Always upload the .drift folder and reports as artifacts for debugging failed builds.
- Check
.driftignoreexcludesnode_modules/,dist/ - Use
--incrementalfor PR checks - Increase timeout:
drift scan --timeout 600 - Scan specific directories:
drift scan src/
- Ensure source files are being scanned (not just config)
- Check language is supported
- Run
drift statusto see what was detected
- Ensure cache key includes source file hashes
- Check cache path is
.drift(not.drift/) - Verify cache is restored before scan
- Check
--fail-onsetting - Review violations with
drift gate --verbose - Approve legitimate patterns:
drift approve <id>
- Git Hooks β Run Drift on commit/push
- Quality Gates β Configure gate policies
- MCP Setup β Connect to AI assistants
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types