O que é CI/CD?
CI (Continuous Integration) é a prática de integrar código frequentemente num repositório partilhado, com testes automáticos.
CD (Continuous Delivery/Deploy) é o processo de entregar alterações de código para produção de forma automática e segura.
Porque automatizar?
- Velocidade: Deploy em minutos, não em horas
- Segurança: Testes automáticos antes de ir para produção
- Consistência: Mesmo processo sempre que houver alteração
- Confiança: Menos erros humanos
GitHub Actions: O tutorial
Passo 1: Criar o workflow
Crie o ficheiro .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- run: npm run test
Passo 2: Adicionar testes
Certifique-se que o seu projeto tem testes configurados:
{
"scripts": {
"test": "vitest run",
"build": "astro build"
}
}
Passo 3: Deploy automático
Para Vercel, Railway ou Netlify, adicione o deploy step:
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
Passo 4: Variáveis de ambiente
Configure os secrets no GitHub:
- Settings → Secrets and variables → Actions
- Adicione
VERCEL_TOKEN,VERCEL_ORG_ID,VERCEL_PROJECT_ID
Boas práticas
- Execute testes antes do deploy
- Use branch protection no
main - Implemente rollback automático
- Notifique a equipa em caso de falha
- Use cache de dependências
Conclusão
CI/CD não é um luxo — é uma necessidade. Comece simples e evolua o pipeline conforme o projeto cresce.
What is CI/CD?
CI (Continuous Integration) is the practice of frequently integrating code into a shared repository, with automated tests.
CD (Continuous Delivery/Deploy) is the process of delivering code changes to production automatically and safely.
Why automate?
- Speed: Deploy in minutes, not hours
- Security: Automated tests before going to production
- Consistency: The same process every time there is a change
- Confidence: Fewer human errors
GitHub Actions: the tutorial
Step 1: Create the workflow
Create the file .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- run: npm run test
Step 2: Add tests
Make sure your project has tests configured:
{
"scripts": {
"test": "vitest run",
"build": "astro build"
}
}
Step 3: Automatic deploy
For Vercel, Railway or Netlify, add the deploy step:
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
Step 4: Environment variables
Configure the secrets on GitHub:
- Settings → Secrets and variables → Actions
- Add
VERCEL_TOKEN,VERCEL_ORG_ID,VERCEL_PROJECT_ID
Best practices
- Run tests before deploying
- Use branch protection on
main - Implement automatic rollback
- Notify the team in case of failure
- Use dependency caching
Conclusion
CI/CD is not a luxury — it is a necessity. Start simple and evolve the pipeline as the project grows.
¿Qué es CI/CD?
CI (Continuous Integration) es la práctica de integrar código frecuentemente en un repositorio compartido, con pruebas automáticas.
CD (Continuous Delivery/Deploy) es el proceso de entregar cambios de código a producción de forma automática y segura.
¿Por qué automatizar?
- Velocidad: Deploy en minutos, no en horas
- Seguridad: Pruebas automáticas antes de ir a producción
- Consistencia: El mismo proceso siempre que haya un cambio
- Confianza: Menos errores humanos
GitHub Actions: el tutorial
Paso 1: Crear el workflow
Crea el archivo .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- run: npm run test
Paso 2: Agregar pruebas
Asegúrate de que tu proyecto tenga pruebas configuradas:
{
"scripts": {
"test": "vitest run",
"build": "astro build"
}
}
Paso 3: Deploy automático
Para Vercel, Railway o Netlify, agrega el paso de deploy:
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
Paso 4: Variables de entorno
Configura los secrets en GitHub:
- Settings → Secrets and variables → Actions
- Agrega
VERCEL_TOKEN,VERCEL_ORG_ID,VERCEL_PROJECT_ID
Buenas prácticas
- Ejecuta pruebas antes del deploy
- Usa branch protection en
main - Implementa rollback automático
- Notifica al equipo en caso de falha
- Usa caché de dependencias
Conclusión
CI/CD no es un lujo — es una necesidad. Empieza simple y evoluciona el pipeline conforme el proyecto crece.