# modules/ci/manifest.yaml
module:
  name: "ci"
  version: "1.0.0"
  description: "Sistema completo de CI/CD con GitHub Actions, GitLab CI y pipelines automatizados"
  category: "devops"
  
triggers:
  - condition: "needs_cicd"
    value: true
  - condition: "wants_automation"
    value: true
  - condition: "deployment_pipeline"
    value: true
  - condition: "testing_automation"
    value: true
  - condition: "code_quality_checks"
    value: true

entry_points:
  github_actions: "templates/github-actions.yml.hbs"
  gitlab_ci: "templates/gitlab-ci.yml.hbs"
  deployment: "templates/deployment.yml.hbs"
  quality_gates: "templates/quality-gates.yml.hbs"
  security_scan: "templates/security-scan.yml.hbs"

dependencies:
  required: []
  optional:
    - "docker"
    - "testing"
    - "logging"
    - "database"

environment_variables:
  required:
    - CI
    - NODE_ENV
  optional:
    - DOCKER_REGISTRY
    - DEPLOY_TOKEN
    - SONAR_TOKEN
    - CODECOV_TOKEN
    - SLACK_WEBHOOK
    - DISCORD_WEBHOOK
    - AWS_ACCESS_KEY_ID
    - AWS_SECRET_ACCESS_KEY
    - HEROKU_API_KEY
    - VERCEL_TOKEN

features:
  - "automated-testing"
  - "code-quality-analysis"
  - "security-scanning"
  - "dependency-vulnerability-check"
  - "automated-deployment"
  - "rollback-capabilities"
  - "environment-promotion"
  - "notification-system"
  - "artifact-management"
  - "cache-optimization"
  - "parallel-execution"
  - "conditional-workflows"

platforms:
  - name: "github-actions"
    description: "GitHub Actions workflows"
    features: ["matrix-builds", "secrets-management", "artifact-storage"]
  - name: "gitlab-ci"
    description: "GitLab CI/CD pipelines"
    features: ["docker-in-docker", "kubernetes-deployment", "review-apps"]
  - name: "jenkins"
    description: "Jenkins pipeline configuration"
    features: ["declarative-pipeline", "blue-ocean", "plugin-ecosystem"]

workflow_stages:
  - name: "validate"
    description: "Code validation and linting"
    jobs: ["lint", "format-check", "type-check"]
  - name: "test"
    description: "Automated testing"
    jobs: ["unit-tests", "integration-tests", "e2e-tests"]
  - name: "quality"
    description: "Code quality analysis"
    jobs: ["sonarqube", "codecov", "dependency-check"]
  - name: "security"
    description: "Security scanning"
    jobs: ["sast", "dependency-scan", "container-scan"]
  - name: "build"
    description: "Application build"
    jobs: ["compile", "bundle", "docker-build"]
  - name: "deploy"
    description: "Deployment to environments"
    jobs: ["deploy-staging", "deploy-production", "rollback"]

generated_files:
  - ".github/workflows/ci.yml"
  - ".github/workflows/cd.yml"
  - ".github/workflows/security.yml"
  - ".gitlab-ci.yml"
  - "Jenkinsfile"
  - "scripts/deploy.sh"
  - "scripts/rollback.sh"
  - "scripts/health-check.sh"
  - ".github/dependabot.yml"
  - "sonar-project.properties"

integration:
  docker_integration:
    - "container-registry-push"
    - "multi-stage-builds"
    - "security-scanning"
  testing_integration:
    - "test-result-reporting"
    - "coverage-reporting"
    - "performance-testing"
  database_integration:
    - "migration-testing"
    - "seed-data-setup"
    - "backup-verification"
  notification_integration:
    - "slack-notifications"
    - "discord-notifications"
    - "email-alerts"

quality_gates:
  - name: "code-coverage"
    threshold: "80%"
    blocking: true
  - name: "security-vulnerabilities"
    threshold: "0 high, 5 medium"
    blocking: true
  - name: "code-duplication"
    threshold: "3%"
    blocking: false
  - name: "maintainability-rating"
    threshold: "A"
    blocking: false

security_scans:
  - name: "sast"
    tool: "CodeQL"
    languages: ["javascript", "typescript"]
  - name: "dependency-check"
    tool: "npm audit"
    severity: "high"
  - name: "container-scan"
    tool: "Trivy"
    target: "docker-image"
  - name: "secrets-scan"
    tool: "GitLeaks"
    target: "repository"

deployment_strategies:
  - name: "blue-green"
    description: "Zero-downtime deployment"
    platforms: ["kubernetes", "aws-ecs"]
  - name: "rolling"
    description: "Gradual instance replacement"
    platforms: ["kubernetes", "docker-swarm"]
  - name: "canary"
    description: "Gradual traffic shifting"
    platforms: ["kubernetes", "istio"]

environments:
  - name: "development"
    auto_deploy: true
    approval_required: false
    tests_required: ["unit", "lint"]
  - name: "staging"
    auto_deploy: true
    approval_required: false
    tests_required: ["unit", "integration", "e2e"]
  - name: "production"
    auto_deploy: false
    approval_required: true
    tests_required: ["unit", "integration", "e2e", "security"]

notifications:
  success:
    - "slack"
    - "discord"
  failure:
    - "slack"
    - "discord"
    - "email"
  deployment:
    - "slack"
    - "teams"

artifacts:
  - name: "build-artifacts"
    path: "dist/"
    retention: "30 days"
  - name: "test-results"
    path: "test-results/"
    retention: "7 days"
  - name: "coverage-reports"
    path: "coverage/"
    retention: "30 days"
  - name: "docker-images"
    registry: "docker-hub"
    retention: "90 days"

caching:
  - name: "node-modules"
    path: "node_modules"
    key: "npm-${{ hashFiles('package-lock.json') }}"
  - name: "build-cache"
    path: ".next/cache"
    key: "build-${{ github.sha }}"
  - name: "docker-layers"
    type: "docker-buildx"
    mode: "max"

usage_examples:
  - "Automated testing on pull requests"
  - "Continuous deployment to staging"
  - "Production deployment with approval"
  - "Security scanning and compliance"
  - "Multi-environment promotion"
  - "Rollback on failure detection"

ai_instructions: |
  Use this module when:
  - User mentions "CI/CD", "automation", "deployment", "testing pipeline"
  - Project needs automated testing and deployment
  - Code quality and security checks are required
  - Multiple environments need to be managed
  
  Configuration steps:
  1. Detect Git platform (GitHub, GitLab, etc.)
  2. Configure appropriate workflow files
  3. Set up quality gates and security scans
  4. Configure deployment environments
  5. Set up notifications and monitoring
  6. Configure secrets and environment variables
  
  Always consider:
  - Testing strategy (unit, integration, e2e)
  - Security scanning requirements
  - Deployment environments and approval processes
  - Notification preferences
  - Artifact storage and retention policies

automation:
  scripts:
    - "setup-ci.sh": "Initialize CI/CD configuration"
    - "deploy.sh": "Deploy to specified environment"
    - "rollback.sh": "Rollback to previous version"
    - "health-check.sh": "Verify deployment health"
    - "promote.sh": "Promote between environments"

testing:
  - "Workflow syntax validation"
  - "Pipeline execution tests"
  - "Deployment simulation"
  - "Rollback verification"
  - "Security scan validation"

performance:
  optimizations:
    - "Parallel job execution"
    - "Intelligent caching strategies"
    - "Conditional workflow triggers"
    - "Artifact optimization"
  metrics:
    - "Pipeline execution time"
    - "Success/failure rates"
    - "Deployment frequency"
    - "Mean time to recovery"

monitoring:
  - "Pipeline execution metrics"
  - "Deployment success rates"
  - "Quality gate compliance"
  - "Security scan results"
  - "Performance benchmarks"

security:
  best_practices:
    - "Secrets management"
    - "Least privilege access"
    - "Audit logging"
    - "Vulnerability scanning"
    - "Compliance checking"
  compliance:
    - "SOC 2 Type II"
    - "ISO 27001"
    - "GDPR compliance"

scaling:
  horizontal:
    - "Multi-region deployments"
    - "Load balancer configuration"
    - "Auto-scaling policies"
  vertical:
    - "Resource optimization"
    - "Performance tuning"

compatibility:
  platforms:
    - "GitHub Actions"
    - "GitLab CI/CD"
    - "Jenkins"
    - "Azure DevOps"
    - "CircleCI"
  deployment_targets:
    - "AWS (EC2, ECS, Lambda)"
    - "Google Cloud (GKE, Cloud Run)"
    - "Azure (AKS, Container Instances)"
    - "Heroku"
    - "Vercel"
    - "Netlify"
  container_registries:
    - "Docker Hub"
    - "GitHub Container Registry"
    - "AWS ECR"
    - "Google Container Registry"
    - "Azure Container Registry"