Compare commits

..

No commits in common. "cfac85275bac8a59e99ccab64ba9ef1b1a60ae6a" and "73174acd736aba48c6bac7ad197a1ec40dba1d8d" have entirely different histories.

2 changed files with 55 additions and 80 deletions

View File

@ -12,9 +12,25 @@ env:
DOMAIN: "academia.ingeniumcodex.com"
jobs:
# Job único: Build, Test y Deploy en K3s (más eficiente en recursos)
build-test-deploy:
# Job 1: Build y Test (obligatorio)
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore & Build
run: dotnet build --configuration Release --verbosity minimal
- name: Run Tests
run: |
dotnet test tests/Domain.Tests --no-build -c Release --verbosity minimal
dotnet test tests/Application.Tests --no-build -c Release --verbosity minimal
# Job 2: Deploy (siempre después de tests)
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
@ -26,29 +42,22 @@ jobs:
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ env.K3S_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
- name: Build, Test & Deploy
- name: Deploy to K3s
run: |
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
set -e
cd ~/academia
# Pull latest changes
echo "=== Pulling latest code ==="
git fetch origin main
git reset --hard origin/main
# Run tests (en el servidor que tiene más recursos)
echo "=== Running tests ==="
dotnet test tests/Domain.Tests --verbosity minimal || exit 1
dotnet test tests/Application.Tests --verbosity minimal || exit 1
# Build Docker images
echo "=== Building images ==="
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S docker build \
# Build images
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S docker build \
-f deploy/docker/Dockerfile.api -t student-api:latest . &
PID_API=$!
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S docker build \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S docker build \
-f deploy/docker/Dockerfile.frontend -t student-frontend:latest . &
PID_FE=$!
@ -56,30 +65,27 @@ jobs:
wait $PID_FE || exit 1
# Import to k3s
echo "=== Importing to K3s ==="
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S sh -c \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S sh -c \
'docker save student-api:latest | k3s ctr images import -'
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S sh -c \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S sh -c \
'docker save student-frontend:latest | k3s ctr images import -'
# Deploy
echo "=== Deploying ==="
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S kubectl apply -k deploy/k3s/
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S kubectl rollout restart \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl apply -k deploy/k3s/
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout restart \
deployment/student-api deployment/student-frontend -n academia
# Wait for rollout
echo "=== Waiting for rollout ==="
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S kubectl rollout status \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
deployment/student-api -n academia --timeout=180s
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S kubectl rollout status \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
deployment/student-frontend -n academia --timeout=60s
ENDSSH
# Smoke Tests en Producción
# Job 3: Smoke Tests en Producción
smoke-tests:
runs-on: ubuntu-latest
needs: build-test-deploy
needs: deploy
steps:
- name: Wait for services
run: sleep 15
@ -87,25 +93,35 @@ jobs:
- name: Health Check API
run: |
response=$(curl -sf https://${{ env.DOMAIN }}/health)
echo "Health: $response"
echo "Health response: $response"
echo "$response" | grep -q '"status":"Healthy"' || exit 1
- name: Frontend Check
run: curl -sf https://${{ env.DOMAIN }}/ | grep -q 'Sistema de Estudiantes' || exit 1
- name: Health Check Frontend
run: |
curl -sf https://${{ env.DOMAIN }}/ | grep -q 'Sistema de Estudiantes' || exit 1
- name: GraphQL Check
- name: GraphQL Endpoint Check
run: |
response=$(curl -sf -X POST https://${{ env.DOMAIN }}/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ subjects { id name } }"}')
echo "GraphQL: $response"
-d '{"query":"{ __typename }"}')
echo "GraphQL response: $response"
echo "$response" | grep -q '"data"' || exit 1
- name: Database Connectivity Check
run: |
response=$(curl -sf https://${{ env.DOMAIN }}/health)
echo "$response" | grep -q '"name":"database","status":"Healthy"' || exit 1
- name: Subjects Query Test
run: |
response=$(curl -sf -X POST https://${{ env.DOMAIN }}/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ subjects { id name credits } }"}')
echo "Subjects response: $response"
echo "$response" | grep -q '"subjects"' || exit 1
- name: Database Check
run: |
curl -sf https://${{ env.DOMAIN }}/health | grep -q '"name":"database","status":"Healthy"' || exit 1
# Rollback si smoke tests fallan
# Job 4: Rollback automático si smoke tests fallan
rollback:
runs-on: ubuntu-latest
needs: smoke-tests
@ -118,9 +134,9 @@ jobs:
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ env.K3S_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
- name: Rollback
- name: Rollback Deployments
run: |
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
echo '${{ secrets.K3S_SUDO_PASS }}' | sudo -S kubectl rollout undo \
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout undo \
deployment/student-api deployment/student-frontend -n academia
ENDSSH

View File

@ -204,13 +204,8 @@ dotnet build
dotnet run --project Host
dotnet watch run --project Host # Hot reload
# Tests - Todos
dotnet test tests/Application.Tests
dotnet test tests/Domain.Tests
dotnet test tests/Integration.Tests
# Tests - Solo Auth
dotnet test tests/Application.Tests --filter "FullyQualifiedName~Auth"
# Tests
dotnet test
# Migraciones EF Core
dotnet ef migrations add <Nombre> -p Adapters/Driven/Persistence -s Host
@ -227,44 +222,8 @@ npx ng serve # Desarrollo
npx ng build --configuration prod # Producción
npx ng test # Tests unitarios
npx ng lint # Linting
# E2E Tests
npx playwright test # Todos
npx playwright test auth.spec.ts # Solo auth
npx playwright test --reporter=html # Con reporte HTML
```
## Tests Automatizados
### Resumen
| Tipo | Cantidad | Estado |
|------|----------|--------|
| Application Tests | 98 | ✅ 100% |
| Domain Tests | 30 | ✅ 100% |
| Integration Tests | 5 | ✅ 100% |
| E2E Tests | 97 | ⚠️ 26% |
| **Total** | **230** | |
### Tests de Auth (Backend)
| Handler | Tests | Cobertura |
|---------|-------|-----------|
| LoginCommand | 6 | Credenciales válidas/inválidas |
| RegisterCommand | 8 | Registro, duplicados, validaciones |
| ResetPasswordCommand | 8 | Reset válido/inválido |
| ActivateAccountCommand | 10 | Activación, expiración, JWT |
### Tests E2E (Playwright)
| Categoría | Tests | Descripción |
|-----------|-------|-------------|
| Autenticación | 15 | Login, registro, reset |
| Control de Acceso | 16 | Roles Admin/Student |
| Reglas de Negocio | 16 | Max 3 materias, mismo profesor |
| Activación | 18 | Flujo completo de activación |
| CRUD | 32 | Estudiantes, inscripciones, compañeros |
### Docker
```bash