-
Notifications
You must be signed in to change notification settings - Fork 0
Unit test functionality #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
06cc67e
719e58c
d8863cc
a7dc26e
9f49166
789da43
80a83b1
f45a66b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| # GitHub Actions Workflows | ||
|
|
||
| Este directorio contiene los workflows de CI/CD para el proyecto Base Angular App. | ||
|
|
||
| ## 📁 Workflows Disponibles | ||
|
|
||
| ### 1. `ci.yml` - Continuous Integration | ||
| **Ejecuta:** En cada push o pull request a `main` o `develop` | ||
|
|
||
| **Tareas:** | ||
| - ✅ Instala dependencias | ||
| - 🔍 Lint del código (si está configurado) | ||
| - 🧪 Ejecuta tests | ||
| - 🏗️ Construye la aplicación para producción | ||
| - 📊 Muestra información del build | ||
| - 📦 Genera artifacts (dist + deployment package) | ||
| - 💾 Guarda artifacts por 30 días | ||
|
|
||
| **Artifacts generados:** | ||
| - `angular-app-dist-{sha}`: Carpeta dist completa | ||
| - `deployment-package-{sha}`: ZIP listo para desplegar | ||
|
|
||
| ### 2. `deploy.yml` - Prepare Release | ||
| **Ejecuta:** | ||
| - Manualmente desde GitHub Actions UI | ||
| - Automáticamente al crear un tag (v1.0.0, v2.1.0, etc.) | ||
|
|
||
| **Tareas:** | ||
| - 🏗️ Build de producción | ||
| - 📦 Genera paquetes TAR.GZ y ZIP | ||
| - 🔐 Crea checksums SHA256 | ||
| - 📋 Incluye nginx.conf | ||
| - 🚀 Crea GitHub Release (si es un tag) | ||
| - 💾 Guarda artifacts por 90 días | ||
|
|
||
| ## 🔐 Configuración (Opcional) | ||
|
|
||
| Los workflows de CI funcionan sin configuración adicional. No necesitas configurar secrets a menos que quieras automatizar despliegues a servicios específicos. | ||
|
|
||
| ### Para Auto-Deploy (Opcional) | ||
|
|
||
| Si quieres desplegar automáticamente a servicios cloud, puedes agregar secrets según el servicio: | ||
|
|
||
| **Digital Ocean:** | ||
| - `DO_API_TOKEN`: Token de API de Digital Ocean | ||
|
|
||
| **AWS:** | ||
| - `AWS_ACCESS_KEY_ID`: Access Key de AWS | ||
| - `AWS_SECRET_ACCESS_KEY`: Secret Key de AWS | ||
| - `AWS_REGION`: Región (ej: us-east-1) | ||
|
|
||
| **Azure:** | ||
| - `AZURE_CREDENTIALS`: JSON con credenciales de service principal | ||
|
|
||
| **Vercel/Netlify:** | ||
| - Conecta directamente desde su dashboard (no requiere secrets) | ||
|
|
||
| ## 🚀 Cómo Usar | ||
|
|
||
| ### Ejecutar Tests Automáticamente | ||
| ```bash | ||
| # Los tests se ejecutan automáticamente en cada push/PR | ||
| git push origin develop | ||
| ``` | ||
|
|
||
| ### Desplegar Manualmente | ||
| 1. Ve a la pestaña "Actions" en GitHub | ||
| 2. Selecciona "CD - Deploy to Server" | ||
| 3. Click en "Run workflow" | ||
| 4. Selecciona la rama y confirma | ||
|
|
||
| ### Desplegar Automáticamente | ||
| ```bash | ||
| # Simplemente haz push a main | ||
| git push origin main | ||
| ```1. Crear Pull Request (Desarrollo) | ||
| ```bash | ||
| # Crea una rama feature | ||
| git checkout -b feature/nueva-funcionalidad | ||
|
|
||
| # Haz tus cambios y commity un resumen al final | ||
| - Recibirás notificaciones por email si algún workflow falla | ||
| - Los artifacts se pueden descargar desde la página del workflow | ||
|
Comment on lines
+76
to
+83
|
||
|
|
||
| ## 🌐 Opciones de Deployment | ||
|
|
||
| Ver [DEPLOYMENT-CLOUD.md](../../DEPLOYMENT-CLOUD.md) para guías detalladas de deployment en: | ||
|
|
||
| - 🌊 **Digital Ocean** (App Platform o Droplet) | ||
| - ☁️ **AWS S3 + CloudFront** | ||
| - 🔷 **Azure Static Web Apps** | ||
| - ▲ **Vercel** (recomendado para simplicidad) | ||
| - 🌐 **Netlify** | ||
| - 📄 **GitHub Pages** (gratis para repos públicos) | ||
|
|
||
| ## 🔧 Troubleshooting | ||
|
|
||
| ### Los tests fallan en GitHub pero pasan localmente | ||
| - Verifica que no dependas de configuraciones locales | ||
| - Asegúrate de que todos los assets de test estén en el repo | ||
| - Revisa las versiones de Node.js (workflow usa 20.x) | ||
|
|
||
| ### Build falla | ||
| - Verifica que todas las dependencias estén en `package.json` | ||
| - Revisa los logs en la pestaña Actions | ||
| - Prueba el build localmente: `npm ci && npm run build` | ||
|
|
||
| ### No se generan artifacts | ||
| - Verifica que el build complete exitosamente | ||
| - Los artifacts solo se generan si todos los pasos anteriores pasan | ||
| - Artifacts de CI duran 30 días, artifacts de release duran 90 días | ||
|
|
||
| ### Error al crear Release | ||
| - Solo se crean releases automáticas para tags que empiecen con "v" | ||
| - Verifica que tengas permisos de escritura en el repo | ||
| - El token `GITHUB_TOKEN` debe tener permiso para crear releases | ||
|
|
||
| ## 📝 Notas | ||
|
|
||
| - **Artifacts de CI**: Se mantienen por 30 días | ||
| - **Artifacts de Release**: Se mantienen por 90 días | ||
| - **GitHub Releases**: Permanentes (hasta que se borren manualmente) | ||
| - Los workflows de CI se ejecutan en pull requests sin acceso a secrets (por seguridad) | ||
| - El deployment es siempre manual o mediante releases para mejor control | ||
| git pull origin main | ||
| git tag -a v1.0.0 -m "Release version 1.0.0" | ||
| git push origin v1.0.0 | ||
| ``` | ||
|
|
||
| Esto: | ||
| - 🏗️ Construye la aplicación | ||
| - 📦 Crea paquetes de deployment | ||
| - 🚀 Genera un GitHub Release con todos los assets | ||
| - 📋 Incluye instrucciones de deploy para cada plataforma | ||
|
|
||
| ### 4. Descargar y Desplegar | ||
|
|
||
| **Opción A: Desde GitHub Release (para tags)** | ||
| 1. Ve a la sección "Releases" en GitHub | ||
| 2. Descarga el archivo que necesites: | ||
| - `.tar.gz` para Linux/Mac | ||
| - `.zip` para Windows | ||
| 3. Sigue las instrucciones de deployment en [DEPLOYMENT-CLOUD.md](../../DEPLOYMENT-CLOUD.md) | ||
|
|
||
| **Opción B: Desde Artifacts (cualquier commit)** | ||
| 1. Ve a la pestaña "Actions" en GitHub | ||
| 2. Selecciona el workflow ejecutado | ||
| 3. Descarga el artifact `deployment-package-{sha}` | ||
| 4. Úsalo para desplegar en tu servicio cloud preferido | ||
|
|
||
| ### 5. Deploy Manual (sin tag) | ||
| ```bash | ||
| # Ejecuta el workflow manualmente | ||
| # Ve a Actions → CD - Prepare Release → Run workflow | ||
| # Especifica una versión (ej: v1.1.0-beta) de tu archivo `nginx.conf` | ||
| - Ejecuta `sudo nginx -t` en el servidor para verificar | ||
|
|
||
| ### Build falla | ||
| - Verifica que todas las dependencias estén en `package.json` | ||
| - Revisa los logs en la pestaña Actions para más detalles | ||
|
|
||
| ## 📝 Notas | ||
|
|
||
| - Los artifacts de build se mantienen por 7 días | ||
| - Cada despliegue crea un backup automático con timestamp | ||
| - El workflow de CI no despliega, solo valida el código | ||
| - El workflow de CD requiere que CI pase exitosamente | ||
|
Comment on lines
+125
to
+167
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: CI - Build and Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main, develop, release/* ] | ||
| pull_request: | ||
| branches: [ main, develop, release/* ] | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [20.x] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: TypeScript syntax check | ||
| run: npm run typecheck | ||
|
|
||
| - name: Run tests | ||
| run: npm test -- --watch=false | ||
|
|
||
| - name: Build application for production | ||
| run: npm run build | ||
|
|
||
| - name: Display build output structure | ||
| run: | | ||
| echo " Build completed successfully!" | ||
| echo "Build output structure:" | ||
| ls -lah dist/ | ||
| if [ -d "dist/base-angular-app/browser" ]; then | ||
| echo "Browser bundle size:" | ||
| du -sh dist/base-angular-app/browser | ||
| fi | ||
|
|
||
| - name: Upload build artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: angular-app-dist-${{ github.sha }} | ||
| path: dist/ | ||
| retention-days: 30 | ||
| compression-level: 9 | ||
|
|
||
| - name: Create deployment package | ||
| run: | | ||
| cd dist | ||
| zip -r ../angular-app-${{ github.sha }}.zip . | ||
| cd .. | ||
| echo " Package size: $(du -h angular-app-${{ github.sha }}.zip | cut -f1)" | ||
|
|
||
| - name: Upload deployment package | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: deployment-package-${{ github.sha }} | ||
| path: angular-app-${{ github.sha }}.zip | ||
| retention-days: 30 | ||
|
|
||
| - name: Summary | ||
| run: | | ||
| echo "### Build Summary" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Node Version:** ${{ matrix.node-version }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo " **Artifacts generated:**" >> $GITHUB_STEP_SUMMARY | ||
| echo "- angular-app-dist-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- deployment-package-${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo " **Ready to deploy to:**" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Digital Ocean" >> $GITHUB_STEP_SUMMARY | ||
| echo "- AWS S3 + CloudFront" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Azure Static Web Apps" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Vercel" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Netlify" >> $GITHUB_STEP_SUMMARY |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,142 @@ | ||||||||||||||
| name: CD - Prepare Release | ||||||||||||||
|
|
||||||||||||||
| # Este workflow prepara releases que pueden desplegarse en cualquier servicio cloud | ||||||||||||||
| # (Digital Ocean, AWS, Azure, Vercel, Netlify, etc.) | ||||||||||||||
|
|
||||||||||||||
| on: | ||||||||||||||
| workflow_dispatch: # Ejecución manual desde GitHub UI | ||||||||||||||
| inputs: | ||||||||||||||
| version: | ||||||||||||||
| description: 'Release version (e.g., v1.0.0)' | ||||||||||||||
| required: false | ||||||||||||||
| default: 'latest' | ||||||||||||||
| push: | ||||||||||||||
| tags: | ||||||||||||||
| - 'v*' # Se activa cuando creas un tag como v1.0.0 | ||||||||||||||
|
|
||||||||||||||
| jobs: | ||||||||||||||
| prepare-release: | ||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||
|
|
||||||||||||||
| steps: | ||||||||||||||
| - name: Checkout code | ||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||
|
|
||||||||||||||
| - name: Setup Node.js | ||||||||||||||
| uses: actions/setup-node@v4 | ||||||||||||||
| with: | ||||||||||||||
| node-version: '20.x' | ||||||||||||||
| cache: 'npm' | ||||||||||||||
|
|
||||||||||||||
| - name: Install dependencies | ||||||||||||||
| run: npm ci | ||||||||||||||
|
|
||||||||||||||
| - name: Build for production | ||||||||||||||
| run: npm run build | ||||||||||||||
|
|
||||||||||||||
| - name: Get version | ||||||||||||||
| id: version | ||||||||||||||
| run: | | ||||||||||||||
| if [ "${{ github.event.inputs.version }}" != "" ]; then | ||||||||||||||
| echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT | ||||||||||||||
| elif [ "${{ github.ref_type }}" == "tag" ]; then | ||||||||||||||
| echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT | ||||||||||||||
| else | ||||||||||||||
| echo "version=latest" >> $GITHUB_OUTPUT | ||||||||||||||
| fi | ||||||||||||||
|
|
||||||||||||||
| - name: Create deployment package | ||||||||||||||
| run: | | ||||||||||||||
| cd dist | ||||||||||||||
| tar -czf ../angular-app-${{ steps.version.outputs.version }}.tar.gz . | ||||||||||||||
| zip -r ../angular-app-${{ steps.version.outputs.version }}.zip . | ||||||||||||||
| cd .. | ||||||||||||||
| echo "📦 Package created:" | ||||||||||||||
| ls -lh angular-app-${{ steps.version.outputs.version }}.* | ||||||||||||||
|
|
||||||||||||||
| - name: Generate checksums | ||||||||||||||
| run: | | ||||||||||||||
| sha256sum angular-app-${{ steps.version.outputs.version }}.tar.gz > checksums.txt | ||||||||||||||
| sha256sum angular-app-${{ steps.version.outputs.version }}.zip >> checksums.txt | ||||||||||||||
| cat checksums.txt | ||||||||||||||
|
|
||||||||||||||
| - name: Upload release artifacts | ||||||||||||||
| uses: actions/upload-artifact@v4 | ||||||||||||||
| with: | ||||||||||||||
| name: release-${{ steps.version.outputs.version }} | ||||||||||||||
| path: | | ||||||||||||||
| angular-app-${{ steps.version.outputs.version }}.tar.gz | ||||||||||||||
| angular-app-${{ steps.version.outputs.version }}.zip | ||||||||||||||
| checksums.txt | ||||||||||||||
| nginx.conf | ||||||||||||||
| retention-days: 90 | ||||||||||||||
|
|
||||||||||||||
| - name: Create GitHub Release | ||||||||||||||
| if: github.ref_type == 'tag' | ||||||||||||||
| uses: softprops/action-gh-release@v1 | ||||||||||||||
| with: | ||||||||||||||
| files: | | ||||||||||||||
| angular-app-${{ steps.version.outputs.version }}.tar.gz | ||||||||||||||
| angular-app-${{ steps.version.outputs.version }}.zip | ||||||||||||||
| checksums.txt | ||||||||||||||
| nginx.conf | ||||||||||||||
|
Comment on lines
+71
to
+82
|
||||||||||||||
| body: | | ||||||||||||||
| ## 🚀 Release ${{ steps.version.outputs.version }} | ||||||||||||||
|
|
||||||||||||||
| ### 📦 Assets | ||||||||||||||
| - `angular-app-${{ steps.version.outputs.version }}.tar.gz` - Producción (Linux/Mac) | ||||||||||||||
| - `angular-app-${{ steps.version.outputs.version }}.zip` - Producción (Windows/Universal) | ||||||||||||||
| - `nginx.conf` - Configuración de Nginx | ||||||||||||||
| - `checksums.txt` - SHA256 checksums | ||||||||||||||
|
|
||||||||||||||
| ### 🌐 Deploy Options | ||||||||||||||
|
|
||||||||||||||
| **Digital Ocean App Platform:** | ||||||||||||||
| ```bash | ||||||||||||||
| doctl apps create --spec .do/app.yaml | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Digital Ocean Droplet:** | ||||||||||||||
| ```bash | ||||||||||||||
| scp angular-app-${{ steps.version.outputs.version }}.tar.gz user@droplet:/tmp/ | ||||||||||||||
| ssh user@droplet | ||||||||||||||
| cd /var/www/html | ||||||||||||||
| tar -xzf /tmp/angular-app-${{ steps.version.outputs.version }}.tar.gz | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **AWS S3 + CloudFront:** | ||||||||||||||
| ```bash | ||||||||||||||
| unzip angular-app-${{ steps.version.outputs.version }}.zip | ||||||||||||||
| aws s3 sync . s3://your-bucket-name/ --delete | ||||||||||||||
| aws cloudfront create-invalidation --distribution-id YOUR_DIST_ID --paths "/*" | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Azure Static Web Apps:** | ||||||||||||||
| ```bash | ||||||||||||||
| az staticwebapp deploy --name your-app-name --source angular-app-${{ steps.version.outputs.version }}.zip | ||||||||||||||
| ``` | ||||||||||||||
| draft: false | ||||||||||||||
| prerelease: false | ||||||||||||||
| env: | ||||||||||||||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||
|
|
||||||||||||||
| - name: Summary | ||||||||||||||
| run: | | ||||||||||||||
| echo "### 🎉 Release Preparado" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| echo "" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| echo "**Versión:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| echo "" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| echo "### 📦 Archivos Generados" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| echo \`\`\`" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
| ls -lh angular-app-* checksums.txt nginx.conf | ||||||||||||||
| echo \`\`\`" >> $GITHUB_STEP_SUMMARY | ||||||||||||||
|
Comment on lines
+130
to
+132
|
||||||||||||||
| echo \`\`\`" >> $GITHUB_STEP_SUMMARY | |
| ls -lh angular-app-* checksums.txt nginx.conf | |
| echo \`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| ls -lh angular-app-* checksums.txt nginx.conf | |
| echo '```' >> $GITHUB_STEP_SUMMARY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow name referenced here is incorrect. According to the deploy.yml file, the workflow is named "CD - Prepare Release", not "CD - Deploy to Server". This inconsistency could confuse users trying to follow the documentation.