82 lines
2.2 KiB
YAML
82 lines
2.2 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
# Triggers: push to main and pull requests to main
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
# Backend build job
|
|
backend-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET 10
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 10.x
|
|
|
|
- name: Restore dependencies
|
|
run: dotnet restore Backend/PruebaGentle.slnx
|
|
|
|
- name: Build backend
|
|
run: dotnet build Backend/PruebaGentle.slnx --configuration Release
|
|
|
|
# Frontend build job
|
|
frontend-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js 22
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22.x
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
working-directory: Frontend
|
|
|
|
- name: Build frontend
|
|
run: npm run build
|
|
working-directory: Frontend
|
|
|
|
- name: Run tests
|
|
run: npm run test:run
|
|
working-directory: Frontend
|
|
|
|
# Docker build job (depends on backend and frontend builds)
|
|
docker-build:
|
|
needs: [backend-build, frontend-build]
|
|
runs-on: docker
|
|
if: github.ref == 'refs/heads/main'
|
|
env:
|
|
DOCKER_API_VERSION: "1.41"
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Build Docker images
|
|
run: docker compose build
|
|
|
|
- name: Tag images
|
|
run: |
|
|
docker tag backend repo.eldiaservicios.com/dmolinari/pruebagentle/backend:latest
|
|
docker tag frontend repo.eldiaservicios.com/dmolinari/pruebagentle/frontend:latest
|
|
|
|
- name: Push to registry
|
|
run: |
|
|
docker push repo.eldiaservicios.com/dmolinari/pruebagentle/backend:latest
|
|
docker push repo.eldiaservicios.com/dmolinari/pruebagentle/frontend:latest
|
|
|
|
- name: Clean up old images
|
|
run: |
|
|
# Keep only the last 2 versions by deleting older tags if they exist
|
|
docker images --format '{{.Repository}}:{{.Tag}}' | grep 'repo.eldiaservicios.com/dmolinari/pruebagentle' | tail -n +3 | xargs -r docker rmi || true |