Skip to main content

CI/CD Integration

Complete guide to integrating Lovelace CLI with continuous integration and deployment pipelines

Overview

Lovelace CLI integrates seamlessly with CI/CD pipelines to provide automated code analysis, AI-powered code review, and intelligent deployment assistance. This guide covers integration patterns for popular CI/CD platforms.

GitHub Actions

Basic Workflow

Create .github/workflows/lovelace.yml:

yaml
name: Lovelace AI Analysis

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  analyze:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        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'
          cache: 'npm'

      - name: Install Lovelace CLI
        run: npm install -g @lovelace-ai/cli

      - name: Authenticate with Lovelace
        run: lovelace auth signin --token ${{ secrets.LOVELACE_TOKEN }}

      - name: Initialize workspace
        run: lovelace workspace init --workspace ${{ github.repository }}

      - name: Run code analysis
        run: |
          lovelace analyze --output json --output-file analysis.json
          lovelace analyze --security --output json --output-file security.json

      - name: Upload analysis results
        uses: actions/upload-artifact@v3
        with:
          name: lovelace-analysis
          path: |
            analysis.json
            security.json

      - name: Comment on PR
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const analysis = JSON.parse(fs.readFileSync('analysis.json', 'utf8'));

            const comment = `## 🤖 Lovelace AI Analysis

            **Code Quality Score**: ${analysis.quality_score}/100
            **Issues Found**: ${analysis.issues.length}
            **Security Concerns**: ${analysis.security_issues.length}

            ${analysis.summary}

            View full analysis in the [workflow artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).`;

            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: comment
            });

Advanced Workflow with Agent Execution

yaml
name: Comprehensive Lovelace Analysis

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  analysis:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Lovelace
        uses: lovelace-ai/setup-action@v1
        with:
          token: ${{ secrets.LOVELACE_TOKEN }}
          workspace: ${{ github.repository }}

      - name: Start agent daemon
        run: lovelace agents daemon start

      - name: Run analysis agents
        run: |
          # Run multiple agents in parallel
          lovelace agents run analysis-worker --task code-quality --async &
          lovelace agents run security-worker --task vulnerability-scan --async &
          lovelace agents run test-worker --task generate-tests --async &

          # Wait for completion
          wait

      - name: Generate documentation
        run: lovelace agents run docs-worker --task api-docs --input ./src/api/

      - name: Create PR review
        run: |
          lovelace chat --provider anthropic --context git,workspace << EOF
          Please review this pull request and provide detailed feedback on:
          1. Code quality and architecture
          2. Security considerations
          3. Testing coverage
          4. Documentation completeness

          Focus on actionable improvements and best practices.
          EOF

      - name: Upload comprehensive report
        uses: actions/upload-artifact@v3
        with:
          name: lovelace-comprehensive-analysis
          path: |
            analysis-*.json
            security-report.json
            test-generation-report.json
            api-docs/

Reusable Action

Create .github/actions/lovelace-analysis/action.yml:

yaml
name: 'Lovelace Analysis'
description: 'Run Lovelace AI analysis on code'

inputs:
  token:
    description: 'Lovelace authentication token'
    required: true
  workspace:
    description: 'Workspace name'
    required: true
  analysis-type:
    description: 'Type of analysis to run'
    required: false
    default: 'full'

outputs:
  quality-score:
    description: 'Code quality score'
    value: ${{ steps.analyze.outputs.quality-score }}

runs:
  using: 'composite'
  steps:
    - name: Install Lovelace CLI
      shell: bash
      run: npm install -g @lovelace-ai/cli

    - name: Authenticate
      shell: bash
      run: lovelace auth signin --token ${{ inputs.token }}

    - name: Initialize workspace
      shell: bash
      run: lovelace workspace init --workspace ${{ inputs.workspace }}

    - name: Run analysis
      id: analyze
      shell: bash
      run: |
        case "${{ inputs.analysis-type }}" in
          "security")
            lovelace analyze --security --output json --output-file analysis.json
            ;;
          "quality")
            lovelace analyze --symbols --dependencies --output json --output-file analysis.json
            ;;
          "full")
            lovelace analyze --output json --output-file analysis.json
            ;;
        esac

        # Extract quality score for output
        SCORE=$(jq -r '.quality_score' analysis.json)
        echo "quality-score=$SCORE" >> $GITHUB_OUTPUT

GitLab CI/CD

Basic Pipeline

Create .gitlab-ci.yml:

yaml
stages:
  - analysis
  - review
  - report

variables:
  NODE_VERSION: "20"

lovelace-analysis:
  stage: analysis
  image: node:${NODE_VERSION}
  before_script:
    - npm install -g @lovelace-ai/cli
    - lovelace auth signin --token $LOVELACE_TOKEN
  script:
    - lovelace workspace init --workspace $CI_PROJECT_NAME
    - lovelace analyze --output json --output-file analysis.json
    - lovelace analyze --security --output json --output-file security.json
  artifacts:
    reports:
      # GitLab security dashboard integration
      sast: security.json
    paths:
      - analysis.json
      - security.json
    expire_in: 1 week
  only:
    - merge_requests
    - main

ai-code-review:
  stage: review
  image: node:${NODE_VERSION}
  dependencies:
    - lovelace-analysis
  before_script:
    - npm install -g @lovelace-ai/cli
    - lovelace auth signin --token $LOVELACE_TOKEN
  script:
    - |
      # Generate AI-powered code review
      lovelace chat --provider anthropic --context git << EOF
      Please review the changes in this merge request:

      $(git diff --name-only $CI_MERGE_REQUEST_TARGET_BRANCH_NAME)

      Provide specific feedback on code quality, security, and best practices.
      EOF > ai-review.md
    - |
      # Post review as MR comment
      curl --request POST \
        --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
        --header "Content-Type: application/json" \
        --data "{\"body\": \"$(cat ai-review.md)\"}" \
        "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes"
  artifacts:
    paths:
      - ai-review.md
  only:
    - merge_requests

generate-report:
  stage: report
  image: node:${NODE_VERSION}
  dependencies:
    - lovelace-analysis
  script:
    - |
      # Generate comprehensive HTML report
      lovelace agents run docs-worker --task analysis-report \
        --input analysis.json --output report.html
  artifacts:
    paths:
      - report.html
    expire_in: 30 days
  only:
    - main

Advanced Pipeline with Quality Gates

yaml
include:
  - template: Security/SAST.gitlab-ci.yml

stages:
  - prepare
  - analyze
  - quality-gate
  - deploy

variables:
  LOVELACE_QUALITY_THRESHOLD: "80"
  LOVELACE_SECURITY_THRESHOLD: "high"

prepare-workspace:
  stage: prepare
  image: node:20
  script:
    - npm install -g @lovelace-ai/cli
    - lovelace auth signin --token $LOVELACE_TOKEN
    - lovelace workspace init --workspace $CI_PROJECT_NAME
    - lovelace workspace sync
  artifacts:
    paths:
      - .lovelace/
  cache:
    key: lovelace-workspace-$CI_COMMIT_REF_SLUG
    paths:
      - .lovelace/

comprehensive-analysis:
  stage: analyze
  image: node:20
  dependencies:
    - prepare-workspace
  parallel:
    matrix:
      - ANALYSIS_TYPE: [quality, security, architecture, dependencies]
  script:
    - npm install -g @lovelace-ai/cli
    - lovelace auth signin --token $LOVELACE_TOKEN
    - |
      case "$ANALYSIS_TYPE" in
        "quality")
          lovelace analyze --symbols --dependencies --output json --output-file quality-analysis.json
          ;;
        "security")
          lovelace analyze --security --output json --output-file security-analysis.json
          ;;
        "architecture")
          lovelace analyze --architecture --output json --output-file architecture-analysis.json
          ;;
        "dependencies")
          lovelace analyze --dependencies --output json --output-file deps-analysis.json
          ;;
      esac
  artifacts:
    paths:
      - "*-analysis.json"

quality-gate:
  stage: quality-gate
  image: node:20
  dependencies:
    - comprehensive-analysis
  script:
    - |
      # Check quality threshold
      QUALITY_SCORE=$(jq -r '.quality_score' quality-analysis.json)
      if [ "$QUALITY_SCORE" -lt "$LOVELACE_QUALITY_THRESHOLD" ]; then
        echo "Quality score $QUALITY_SCORE below threshold $LOVELACE_QUALITY_THRESHOLD"
        exit 1
      fi
    - |
      # Check security issues
      SECURITY_ISSUES=$(jq -r '.critical_issues | length' security-analysis.json)
      if [ "$SECURITY_ISSUES" -gt 0 ]; then
        echo "Found $SECURITY_ISSUES critical security issues"
        exit 1
      fi
    - echo "Quality gate passed!"
  allow_failure: false

Azure DevOps

Basic Pipeline

Create azure-pipelines.yml:

yaml
trigger:
  branches:
    include:
      - main
      - develop

pr:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

variables:
  nodeVersion: '20.x'

stages:
- stage: Analysis
  displayName: 'Lovelace Analysis'
  jobs:
  - job: CodeAnalysis
    displayName: 'Code Analysis'
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: $(nodeVersion)
      displayName: 'Setup Node.js'

    - script: |
        npm install -g @lovelace-ai/cli
      displayName: 'Install Lovelace CLI'

    - script: |
        lovelace auth signin --token $(LOVELACE_TOKEN)
      displayName: 'Authenticate with Lovelace'
      env:
        LOVELACE_TOKEN: $(LOVELACE_TOKEN)

    - script: |
        lovelace workspace init --workspace $(Build.Repository.Name)
        lovelace analyze --output json --output-file $(Build.ArtifactStagingDirectory)/analysis.json
      displayName: 'Run Analysis'

    - task: PublishBuildArtifacts@1
      inputs:
        pathToPublish: '$(Build.ArtifactStagingDirectory)'
        artifactName: 'lovelace-analysis'
      displayName: 'Publish Analysis Results'

- stage: Review
  displayName: 'AI Code Review'
  condition: eq(variables['Build.Reason'], 'PullRequest')
  dependsOn: Analysis
  jobs:
  - job: AIReview
    displayName: 'AI Code Review'
    steps:
    - task: DownloadBuildArtifacts@0
      inputs:
        artifactName: 'lovelace-analysis'
        downloadPath: '$(System.ArtifactsDirectory)'

    - script: |
        npm install -g @lovelace-ai/cli
        lovelace auth signin --token $(LOVELACE_TOKEN)
      env:
        LOVELACE_TOKEN: $(LOVELACE_TOKEN)

    - script: |
        # Generate AI review
        lovelace chat --provider anthropic --context git > ai-review.md

        # Post as PR comment using Azure DevOps REST API
        curl -X POST \
          -H "Authorization: Bearer $(System.AccessToken)" \
          -H "Content-Type: application/json" \
          -d "{\"comments\":[{\"parentCommentId\":0,\"content\":\"$(cat ai-review.md)\",\"commentType\":1}]}" \
          "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)/threads?api-version=6.0"
      displayName: 'Generate and Post AI Review'

Jenkins

Declarative Pipeline

Create Jenkinsfile:

groovy
pipeline {
    agent any

    environment {
        LOVELACE_TOKEN = credentials('lovelace-token')
        NODE_VERSION = '20'
    }

    stages {
        stage('Setup') {
            steps {
                script {
                    // Install Node.js
                    def nodeHome = tool name: 'NodeJS', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
                    env.PATH = "${nodeHome}/bin:${env.PATH}"
                }

                sh 'npm install -g @lovelace-ai/cli'
                sh 'lovelace auth signin --token $LOVELACE_TOKEN'
            }
        }

        stage('Initialize Workspace') {
            steps {
                sh 'lovelace workspace init --workspace ${JOB_NAME}'
            }
        }

        stage('Analysis') {
            parallel {
                stage('Code Quality') {
                    steps {
                        sh 'lovelace analyze --symbols --dependencies --output json --output-file quality-analysis.json'
                    }
                    post {
                        always {
                            archiveArtifacts artifacts: 'quality-analysis.json', fingerprint: true
                        }
                    }
                }

                stage('Security Scan') {
                    steps {
                        sh 'lovelace analyze --security --output json --output-file security-analysis.json'
                    }
                    post {
                        always {
                            archiveArtifacts artifacts: 'security-analysis.json', fingerprint: true
                        }
                    }
                }

                stage('Agent Tasks') {
                    steps {
                        sh '''
                            lovelace agents daemon start
                            lovelace agents run analysis-worker --task architecture-review --async
                            lovelace agents run test-worker --task coverage-analysis --async
                        '''
                    }
                }
            }
        }

        stage('Quality Gate') {
            steps {
                script {
                    def analysis = readJSON file: 'quality-analysis.json'
                    if (analysis.quality_score < 80) {
                        error "Quality score ${analysis.quality_score} below threshold 80"
                    }

                    def security = readJSON file: 'security-analysis.json'
                    if (security.critical_issues.size() > 0) {
                        error "Found ${security.critical_issues.size()} critical security issues"
                    }
                }
            }
        }

        stage('AI Review') {
            when {
                changeRequest()
            }
            steps {
                sh '''
                    lovelace chat --provider anthropic --context git << EOF
                    Please review this pull request and provide feedback on:
                    1. Code quality improvements
                    2. Security considerations
                    3. Architecture decisions

                    Focus on actionable recommendations.
                    EOF > ai-review.md
                '''

                script {
                    def review = readFile 'ai-review.md'
                    pullRequest.comment(review)
                }
            }
        }
    }

    post {
        always {
            sh 'lovelace agents daemon stop'
            cleanWs()
        }

        success {
            echo 'Lovelace analysis completed successfully!'
        }

        failure {
            echo 'Lovelace analysis failed. Check the logs for details.'
        }
    }
}

CircleCI

Configuration

Create .circleci/config.yml:

yaml
version: 2.1

orbs:
  node: circleci/node@5.1.0

executors:
  lovelace-executor:
    docker:
      - image: cimg/node:20.0
    resource_class: large

commands:
  setup-lovelace:
    steps:
      - run:
          name: Install Lovelace CLI
          command: npm install -g @lovelace-ai/cli
      - run:
          name: Authenticate
          command: lovelace auth signin --token $LOVELACE_TOKEN

jobs:
  analyze:
    executor: lovelace-executor
    steps:
      - checkout
      - setup-lovelace
      - run:
          name: Initialize workspace
          command: lovelace workspace init --workspace $CIRCLE_PROJECT_REPONAME
      - run:
          name: Run comprehensive analysis
          command: |
            lovelace analyze --output json --output-file analysis.json
            lovelace analyze --security --output json --output-file security.json
      - store_artifacts:
          path: analysis.json
      - store_artifacts:
          path: security.json
      - persist_to_workspace:
          root: .
          paths:
            - analysis.json
            - security.json

  ai-review:
    executor: lovelace-executor
    steps:
      - checkout
      - attach_workspace:
          at: .
      - setup-lovelace
      - run:
          name: Generate AI review
          command: |
            lovelace chat --provider anthropic --context git > ai-review.md
      - run:
          name: Post PR comment
          command: |
            if [ -n "$CIRCLE_PULL_REQUEST" ]; then
              PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST | sed 's/.*\/pull\///')
              gh pr comment $PR_NUMBER --body-file ai-review.md
            fi

  quality-gate:
    executor: lovelace-executor
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Check quality thresholds
          command: |
            QUALITY_SCORE=$(jq -r '.quality_score' analysis.json)
            if [ "$QUALITY_SCORE" -lt 80 ]; then
              echo "Quality score $QUALITY_SCORE below threshold 80"
              exit 1
            fi

            CRITICAL_ISSUES=$(jq -r '.critical_issues | length' security.json)
            if [ "$CRITICAL_ISSUES" -gt 0 ]; then
              echo "Found $CRITICAL_ISSUES critical security issues"
              exit 1
            fi

workflows:
  lovelace-analysis:
    jobs:
      - analyze
      - ai-review:
          requires:
            - analyze
          filters:
            branches:
              ignore: main
      - quality-gate:
          requires:
            - analyze

Best Practices

Security

  1. Store tokens securely: Use CI/CD platform secret management
  2. Limit permissions: Use least-privilege tokens
  3. Audit access: Monitor token usage and access patterns
  4. Rotate tokens: Regularly rotate authentication tokens

Performance

  1. Cache dependencies: Cache Lovelace CLI installation and workspace data
  2. Parallel execution: Run different analysis types in parallel
  3. Incremental analysis: Only analyze changed files when appropriate
  4. Resource allocation: Allocate sufficient CPU and memory for analysis

Integration Patterns

  1. Quality gates: Use analysis results to block deployments
  2. Progressive analysis: Start with basic analysis, add more over time
  3. Contextual feedback: Provide specific, actionable feedback
  4. Artifact management: Store and version analysis results

Monitoring

  1. Track metrics: Monitor analysis completion rates and timing
  2. Alert on failures: Set up alerts for analysis failures
  3. Quality trends: Track code quality improvements over time
  4. Usage analytics: Monitor which features are most valuable

Troubleshooting

Common Issues

Authentication failures:

bash
# Check token validity
lovelace auth status

# Verify token in CI environment
echo $LOVELACE_TOKEN | head -c 20

Workspace initialization failures:

bash
# Check workspace permissions
lovelace workspace list

# Initialize with explicit workspace
lovelace workspace init --workspace explicit-name

Analysis timeouts:

bash
# Increase timeout
lovelace config set analysis.timeout 600

# Run with reduced scope
lovelace analyze --files "src/**/*.ts"

See Also: