CI/CD a Prueba de Balas
Ahora vamos a enfocarnos en automatizar el despliegue a produccion. El objetivo: nunca mas codigo roto en produccion.
El Prompt Maestro
Proba algo como esto:
I need a rock-solid CI/CD pipeline for our finance tracker. Here's what I want to happen:
For every pull request:
- Run the full test suite (unit, integration, E2E)
- Check TypeScript compilation
- Verify code formatting with Prettier
- Run ESLint for code quality issues
- Build the production bundle successfully
- Run security audits on dependencies
- Check for any breaking changes
For main branch merges:
- Everything from PR checks
- Deploy to a staging environment automatically
- Run smoke tests against staging
- Send a Slack notification about deployment status
For tagged releases:
- Deploy to production with zero downtime
- Run post-deployment health checks
- Update monitoring dashboards
Make this bulletproof - I never want broken code to reach production.Que Crea Claude
Con este prompt, Claude genera:
1. GitHub Actions Workflow
# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm run type-check
- run: npm run lint
- run: npm run format:check
- run: npm test -- --coverage
- run: npm run build
e2e:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx playwright install
- run: npm run test:e2e
deploy-staging:
needs: [test, e2e]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run deploy:staging2. Scripts de NPM
{
"scripts": {
"type-check": "tsc --noEmit",
"lint": "eslint . --ext .ts,.tsx",
"format:check": "prettier --check .",
"test": "jest",
"test:e2e": "playwright test",
"deploy:staging": "vercel --prod",
"deploy:production": "vercel --prod --env production"
}
}3. Configuracion de Ambiente
Claude configura variables de entorno, secrets de GitHub, y conexiones con tu hosting.
Integracion con Tu Hosting
Claude conoce todos los servicios populares:
- Vercel - El mas simple, zero config
- Railway - Bueno para backends
- Fly.io - Edge deployment
- AWS - Full control, mas complejo
Simplemente decile cual usas y adapta el pipeline.
Workflow de PR
Con el pipeline configurado, cada PR automaticamente:
- Corre todos los tests
- Valida types y linting
- Buildea para verificar que no hay errores
- Reporta el status en el PR
Si algo falla, el merge se bloquea.
Deploy Stages
Staging
Cada merge a main despliega automaticamente a staging. Esto te da:
- Ambiente identico a produccion
- Lugar para testear antes del release
- Smoke tests automaticos
Production
Los releases taggeados van a produccion:
git tag v1.2.0
git push origin v1.2.0Esto triggerea:
- Build de produccion
- Deploy con zero downtime
- Health checks automaticos
- Notificacion de exito/fallo
Notificaciones
Claude puede configurar notificaciones a:
- Slack - Canal del equipo
- Discord - Servidor de desarrollo
- Email - Para releases importantes
Ejemplo de mensaje de Slack:
:white_check_mark: Deployed v1.2.0 to production
- 3 new features
- 2 bug fixes
- All health checks passing
Rollback Automatico
Para safety extra, podes pedir:
Agrega rollback automatico si los health checks fallan despues del deploy
Claude configura:
- Health check endpoint en tu app
- Verificacion post-deploy
- Rollback a version anterior si falla
- Alerta al equipo
Optimizacion de Performance del Pipeline
Caching
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}Paralelizacion
jobs:
test:
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- run: npm test -- --shard=${{ matrix.shard }}/4Build Artifacts
- uses: actions/upload-artifact@v4
with:
name: build
path: dist/Mi Setup Real
En mis proyectos uso:
- PR: Tests + lint + type-check + build (~3 min)
- Main: Todo lo anterior + deploy staging (~5 min)
- Tags: Deploy production + smoke tests (~7 min)
Con caching agresivo, los tiempos bajan 40%.
Siguiente Paso
Ahora tenes todo automatizado. En la proxima leccion, vamos a armar tu plan de accion de 7 dias para dominar Claude Code.