CI/CD Monitor Server

Panoramica

Il server cicd-monitor e' il ponte tra MCP Suite e le pipeline di Continuous Integration e Continuous Deployment. Si integra nativamente con GitHub Actions tramite la CLI gh, permettendo di monitorare workflow run, visualizzare log di build e identificare test instabili (flaky) senza lasciare l'ambiente di sviluppo.

Il problema principale che risolve e' la frammentazione dell'informazione: gli sviluppatori devono navigare all'interfaccia web di GitHub per controllare lo stato delle build, leggere i log di errore e capire quali test falliscono in modo intermittente. Questo server porta tutte queste informazioni direttamente nell'IDE.

+------------------------------------------------------------+
|               cicd-monitor server                          |
|                                                            |
|  +-------------------------------------------------------+ |
|  |                  Tool Layer                           | |
|  |                                                       | |
|  |  list-pipelines       get-pipeline-status             | |
|  |  get-build-logs       get-flaky-tests                 | |
|  +-------------------------------------------------------+ |
|                           |                                |
|                           v                                |
|  +-------------------------------------------------------+ |
|  |          child_process.execSync                       | |
|  |          Comandi: gh run list / gh run view           | |
|  +-------------------------------------------------------+ |
|                           |                                |
|                           v                                |
|  +-------------------------------------------------------+ |
|  |   Event Bus                                           | |
|  |   cicd:pipeline-completed                             | |
|  |   cicd:build-failed                                   | |
|  +-------------------------------------------------------+ |
+------------------------------------------------------------+

Prerequisiti

  • GitHub CLI (gh) installata e autenticata (gh auth login)
  • Accesso al repository GitHub target (proprietario o collaboratore)

Caratteristiche principali

  • Monitoraggio pipeline: lista e dettaglio dei workflow run recenti
  • Visualizzazione log: accesso diretto ai log di build fino a 10MB
  • Rilevamento flaky test: analisi statistica dei risultati misti pass/fail
  • Pubblicazione eventi: notifica automatica di pipeline completate e build fallite

Tabella dei Tool

[object Object],[object Object],[object Object] undefined

Architettura

Comandi GitHub CLI utilizzati

[object Object],[object Object],[object Object] undefined

Flusso di list-pipelines

  gh run list --json databaseId,displayTitle,headBranch,
                     event,status,conclusion,createdAt,
                     updatedAt,url,workflowName
        |
        v
  JSON.parse(output)
        |
        v
  Mappatura a formato semplificato:
  { id, title, branch, event, status, conclusion,
    workflow, createdAt, updatedAt, url }

Flusso di get-pipeline-status

  gh run view <runId> --json (run fields)
        |
        v
  Run details: id, title, branch, sha, event, status,
               conclusion, workflow, createdAt, updatedAt

  gh run view <runId> --json jobs
        |
        v
  Jobs array:
    +-- Job 1: { name, status, conclusion, startedAt, completedAt }
    |     +-- Step 1: { name, status, conclusion, number }
    |     +-- Step 2: ...
    +-- Job 2: ...

  Se conclusion == 'failure':
    -> Pubblica cicd:pipeline-completed (status: 'failed')
    -> Pubblica cicd:build-failed con nome del job fallito

  Se conclusion == 'success':
    -> Pubblica cicd:pipeline-completed (status: 'success')

Flusso di get-flaky-tests

L'algoritmo per identificare i test flaky e' il seguente:

  1. Recupera gli ultimi N run (default 20)
         |
         v
  2. Raggruppa per branch + workflow
         |
         v
  3. Per ogni gruppo con risultati MISTI (success + failure):
     a. Campiona fino a 5 run
     b. Per ogni run, recupera jobs e steps
     c. Per ogni step, traccia passaggi/fallimenti
         |
         v
  4. Identifica step con ENTRAMBI passCount > 0 E failCount > 0
         |
         v
  5. Calcolo flakiness rate:
     rate = min(passCount, failCount) / totalRuns * 100
         |
         v
  6. Ordina per flakiness rate decrescente

Integrazione Event Bus

Eventi pubblicati

[object Object],[object Object],[object Object],[object Object] undefined

Eventi sottoscritti

Nessuno.

Calcolo durata pipeline

La durata viene calcolata come differenza tra updatedAt e createdAt in millisecondi.


Interazioni con altri server

+------------------+   cicd:pipeline-completed   +-----------------+
|  cicd-monitor    | --------------------------> | standup-notes   |
|                  |   cicd:build-failed         | agile-metrics   |
+------------------+ --------------------------> +-----------------+

+------------------+                             +-----------------+
|  log-analyzer    | <--- (analisi log build)    | cicd-monitor    |
+------------------+                             +-----------------+
[object Object],[object Object],[object Object] undefined

Esempi di utilizzo

Lista pipeline recenti

Richiesta:

{
  "tool": "list-pipelines",
  "arguments": {
    "repo": "my-org/my-project",
    "limit": 5
  }
}

Risposta:

{
  "total": 5,
  "runs": [
    {
      "id": 12345678,
      "title": "feat: add user authentication",
      "branch": "feature/auth",
      "event": "push",
      "status": "completed",
      "conclusion": "success",
      "workflow": "CI",
      "createdAt": "2024-06-15T10:00:00Z",
      "url": "https://github.com/my-org/my-project/actions/runs/12345678"
    }
  ]
}

Stato dettagliato pipeline

Richiesta:

{
  "tool": "get-pipeline-status",
  "arguments": {
    "runId": "12345678",
    "repo": "my-org/my-project"
  }
}

Risposta (semplificata):

{
  "id": 12345678,
  "title": "feat: add user authentication",
  "branch": "feature/auth",
  "sha": "abc123def456",
  "conclusion": "failure",
  "jobs": [
    {
      "name": "build",
      "conclusion": "success",
      "steps": [
        { "name": "Checkout", "conclusion": "success", "number": 1 },
        { "name": "Install", "conclusion": "success", "number": 2 },
        { "name": "Build", "conclusion": "success", "number": 3 }
      ]
    },
    {
      "name": "test",
      "conclusion": "failure",
      "steps": [
        { "name": "Run tests", "conclusion": "failure", "number": 1 }
      ]
    }
  ]
}

Rilevamento test flaky

Richiesta:

{
  "tool": "get-flaky-tests",
  "arguments": {
    "repo": "my-org/my-project",
    "branch": "main",
    "runs": 20
  }
}

Risposta:

{
  "analyzedRuns": 20,
  "branchesAnalyzed": 1,
  "flakyStepsFound": 2,
  "flaky": [
    {
      "branch": "main",
      "workflow": "CI",
      "job": "test",
      "step": "Run integration tests",
      "passCount": 3,
      "failCount": 2,
      "totalRuns": 5,
      "flakinessRate": 40.0
    }
  ]
}

Sviluppi futuri

  • Supporto multi-piattaforma: GitLab CI, Bitbucket Pipelines, Jenkins
  • Caching intelligente: evitare chiamate API ripetute per run gia' analizzati
  • Alert in tempo reale: polling periodico con notifica immediata di fallimenti
  • Analisi trend: tracciamento storico del tasso di successo nel tempo
  • Retry automatico: possibilita' di ri-eseguire un workflow run fallito
  • Correlazione con commit: collegamento automatico tra fallimento e commit specifico
  • Dashboard metriche: lead time, cycle time, deployment frequency (DORA metrics)
  • Integrazione Slack/Teams: notifiche push verso canali di comunicazione