diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml deleted file mode 100644 index 4f45498..0000000 --- a/.gitea/workflows/deploy.yml +++ /dev/null @@ -1,99 +0,0 @@ -name: Deploy Webzine - -on: - push: - branches: - - main - workflow_dispatch: - -jobs: - # ───────────────────────────────────────────── - # COMPILATION — commun aux deux branches - # ───────────────────────────────────────────── - build: - name: Build & Push Docker Image - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - # Le tag d'image dépend de la branche : - # main → webzine:latest - - name: Set image tag - id: vars - run: | - echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT - echo "ENV_LABEL=production" >> $GITHUB_OUTPUT - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # Connexion au registry Gitea intégré - - name: Log in to Gitea Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ vars.REGISTRY_URL }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - # Construction et publication de l'image Docker - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./Webzine.WebApplication/Dockerfile - push: true - tags: ${{ vars.REGISTRY_URL }}/webzine/webzine:${{ steps.vars.outputs.IMAGE_TAG }} - cache-from: type=registry,ref=${{ vars.REGISTRY_URL }}/webzine/webzine:buildcache-${{ steps.vars.outputs.IMAGE_TAG }} - cache-to: type=registry,ref=${{ vars.REGISTRY_URL }}/webzine/webzine:buildcache-${{ steps.vars.outputs.IMAGE_TAG }},mode=max - - outputs: - image_tag: ${{ steps.vars.outputs.IMAGE_TAG }} - env_label: ${{ steps.vars.outputs.ENV_LABEL }} - - # ───────────────────────────────────────────── - # DÉPLOIEMENT — Serveur de PRODUCTION (branche main) - # ───────────────────────────────────────────── - deploy-production: - name: Deploy to Production - needs: build - runs-on: ubuntu-latest - - steps: - - name: Deploy via SSH to PRODUCTION server - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.PROD_HOST }} - username: ${{ secrets.PROD_USER }} - key: ${{ secrets.PROD_SSH_KEY }} - port: ${{ secrets.PROD_SSH_PORT || 22 }} - script: | - set -e - - echo "=== [PROD] Récupération de l'image ===" - docker login ${{ vars.REGISTRY_URL }} \ - -u ${{ secrets.REGISTRY_USERNAME }} \ - -p ${{ secrets.REGISTRY_PASSWORD }} - - docker pull ${{ vars.REGISTRY_URL }}/webzine/webzine:latest - - echo "=== [PROD] Arrêt de l'ancien conteneur ===" - docker stop webzine-prod 2>/dev/null || true - docker rm webzine-prod 2>/dev/null || true - - echo "=== [PROD] Démarrage du nouveau conteneur ===" - docker run -d \ - --name webzine-prod \ - --restart unless-stopped \ - -p 80:8080 \ - -p 443:8081 \ - -v /opt/webzine/prod/data:/app/Data \ - -v /opt/webzine/prod/logs:/Logs \ - -e ASPNETCORE_ENVIRONMENT=Production \ - ${{ vars.REGISTRY_URL }}/webzine/webzine:latest - - echo "=== [PROD] Nettoyage des anciennes images ===" - docker image prune -f - - echo "=== [PROD] Déploiement terminé ===" \ No newline at end of file diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index c67fab3..427f687 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -1,11 +1,6 @@ name: PR Endpoint Performance Check -on: - pull_request: - branches: - - main - - master - - develop +on: [pull_request] jobs: endpoint-performance-check: @@ -13,42 +8,41 @@ jobs: runs-on: ubuntu-latest steps: - # ───────────────────────────────────────────── - # Récupération du code source - # ───────────────────────────────────────────── - name: Checkout PR branch uses: actions/checkout@v4 - # ───────────────────────────────────────────── - # Installation de .NET 10 - # ───────────────────────────────────────────── + - name: Configure appsettings for CI + run: | + # Find the appsettings.json file + APPSETTINGS_PATH="Webzine.WebApplication/appsettings.json" + + # Backup original file + cp $APPSETTINGS_PATH $APPSETTINGS_PATH.bak + + # Use jq to modify the JSON + jq '.UseDatabase = true | .IsSQLite = true' $APPSETTINGS_PATH > $APPSETTINGS_PATH.tmp + mv $APPSETTINGS_PATH.tmp $APPSETTINGS_PATH + + echo "Updated appsettings.json:" + cat $APPSETTINGS_PATH + - name: Setup .NET 10 uses: actions/setup-dotnet@v4 with: dotnet-version: "10.0.x" - # ───────────────────────────────────────────── - # Restauration des dépendances et compilation - # ───────────────────────────────────────────── - name: Restore dependencies run: dotnet restore Webzine.sln - name: Build solution run: dotnet build Webzine.sln --no-restore --configuration Release - # ───────────────────────────────────────────── - # Exécution des tests unitaires (entités) - # ───────────────────────────────────────────── - name: Run unit tests run: | dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \ --no-build \ - --configuration Release \ - --logger "console;verbosity=normal" + --configuration Release - # ───────────────────────────────────────────── - # Démarrage de l'application web en arrière-plan - # ───────────────────────────────────────────── - name: Start Webzine application run: | dotnet run \ @@ -63,70 +57,94 @@ jobs: sleep 1 done ' - echo "Application prête !" + echo "Application prête!" - # ───────────────────────────────────────────── - # Exécution des tests de performance des endpoints - # ───────────────────────────────────────────── - name: Test endpoint response times id: perf_test run: | chmod +x scripts/test-endpoints.sh - bash scripts/test-endpoints.sh http://localhost:5038 1000 || true - FAIL_COUNT=$(grep -c "^\[FAIL\]\|^\[SLOW\]" /tmp/webzine_endpoint_report.txt || echo 0) + bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt + EXIT_CODE=${PIPESTATUS[0]} + + # Count failures + FAIL_COUNT=$(grep -cE "^\[ÉCHEC\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) + SLOW_COUNT=$(grep -cE "^\[LENT\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) + echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT" + echo "slow=$SLOW_COUNT" >> "$GITHUB_OUTPUT" + + # Échoue s’il y a DES problèmes (échecs OU lents) + if [ $FAIL_COUNT -gt 0 ] || [ $SLOW_COUNT -gt 0 ]; then + echo "❌ Performance check failed: $FAIL_COUNT endpoint(s) failed, $SLOW_COUNT endpoint(s) exceeded threshold (1000ms)" + exit 1 + fi + + echo "✅ All endpoints passed performance check (< 1000ms)" - # ───────────────────────────────────────────── - # Publication du rapport en commentaire de PR - # ───────────────────────────────────────────── - name: Post performance report as PR comment - if: always() + if: always() # Always post comment, even on failure env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_SERVER_URL: ${{ gitea.server_url }} REPO: ${{ gitea.repository }} PR_NUMBER: ${{ gitea.event.pull_request.number }} run: | - REPORT_CONTENT=$(cat /tmp/webzine_endpoint_report.txt 2>/dev/null || echo "Aucun rapport généré.") + RAW_REPORT=$(cat /tmp/webzine_endpoint_output.txt 2>/dev/null || echo "Aucune sortie capturée.") FAILED_COUNT="${{ steps.perf_test.outputs.failed }}" - - if [ "${FAILED_COUNT:-0}" -gt 0 ]; then - HEADER="## ❌ Vérification des performances ÉCHOUÉE" - INTRO="${FAILED_COUNT} endpoint(s) ont dépassé 1 seconde ou retourné une erreur serveur." + SLOW_COUNT="${{ steps.perf_test.outputs.slow }}" + + # Determine if the check passed or failed + if [ "$FAILED_COUNT" -gt 0 ] || [ "$SLOW_COUNT" -gt 0 ]; then + STATUS_HEADER="❌ **PERFORMANCE CHECK FAILED**" + STATUS_ICON="❌" else - HEADER="## ✅ Vérification des performances RÉUSSIE" - INTRO="Tous les endpoints ont répondu en moins d'une seconde." + STATUS_HEADER="✅ **PERFORMANCE CHECK PASSED**" + STATUS_ICON="✅" fi - + + # Convert report to Markdown with colors + CLEAN_REPORT=$(echo "$RAW_REPORT" | sed 's/\x1b\[[0-9;]*m//g') + + # Generate formatted report + FORMATTED_REPORT=$(echo "$CLEAN_REPORT" | sed \ + -e 's/^\[OK\] /✅ /' \ + -e 's/^\[LENT\] /⚠️ /' \ + -e 's/^\[ÉCHEC\] /❌ /' \ + -e 's/^→ \[LENT\] / • ⚠️ /' \ + -e 's/^→ \[ÉCHEC\] / • ❌ /' \ + -e 's/^→ / • /' \ + -e 's/^── \(.*\)$/\n### ── \1/' \ + -e 's/^\(Total.*\)$/\n**\1**/' \ + -e 's/^\(Réussis.*\)$/**✅ \1**/' \ + -e 's/^\(Échecs.*\)$/**❌ \1**/' \ + -e 's/^\(⚠️ ENDPOINTS LENTS.*\)$/\n### \1/' \ + -e 's/^\(❌ ENDPOINTS EN ÉCHEC.*\)$/\n### \1/' \ + -e 's/^\(La PR doit.*\)$/\n**❌ \1**/') + BODY=$(cat < Seuil : **1000ms** | Vérifié par le workflow **PR Endpoint Performance**. + $STATUS_HEADER + + $FORMATTED_REPORT + + --- + **Seuil**: 1000ms + **Statistiques**: + - ✅ Endpoints rapides: \$(grep -c "^\[OK\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) + - ⚠️ Endpoints lents (>1000ms): $SLOW_COUNT + - ❌ Endpoints en échec: $FAILED_COUNT + + **Vérifié par**: Workflow PR Endpoint Performance EOF ) - + curl -s -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg body "$BODY" '{body: $body}')" \ "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" - # ───────────────────────────────────────────── - # Blocage de la PR si un endpoint a échoué - # ───────────────────────────────────────────── - - name: Enforce performance gate + - name: Fail job if performance issues detected + if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0 run: | - FAILED="${{ steps.perf_test.outputs.failed }}" - if [ "${FAILED:-0}" -gt 0 ]; then - echo "❌ PR REJETÉE : ${FAILED} endpoint(s) n'ont pas respecté le seuil d'une seconde." - echo " Corrigez les endpoints lents ou en erreur avant de fusionner." - exit 1 - else - echo "✅ Tous les endpoints ont passé le contrôle de performance." - fi \ No newline at end of file + echo "❌ Job failed due to performance issues" + exit 1 \ No newline at end of file diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index 5f298a3..b87a6b3 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -103,12 +103,6 @@ namespace Webzine.Repository .Include(a => a.Titres) .FirstOrDefault(a => a.Nom == nom); - if (artiste == null) - { - this.logger.LogWarning("Pas d'artiste au nom {Nom}", nom); - artiste = new Artiste(); - } - return artiste; } catch (Exception ex) diff --git a/Webzine.WebApplication/Controllers/ArtisteController.cs b/Webzine.WebApplication/Controllers/ArtisteController.cs index 6f395d2..900ec19 100644 --- a/Webzine.WebApplication/Controllers/ArtisteController.cs +++ b/Webzine.WebApplication/Controllers/ArtisteController.cs @@ -36,7 +36,7 @@ if (string.IsNullOrEmpty(nom)) { this.logger.LogWarning("Nom de l'artiste manquant dans la requête."); - return RedirectToAction("Index"); + return this.RedirectToAction("Index", "Accueil"); } // On transforme "fatal-bazooka" en "Fatal Bazooka" pour la factory @@ -46,26 +46,26 @@ // On appelle la factory pour obtenir l'artiste unique var artiste = this._artisteRepository.FindByName(nomPropre); + // Check if artiste was found if (artiste == null) { - this.logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre); - return RedirectToAction("Index"); + this.logger.LogWarning("Artiste non trouvé avec le nom : {NomArtiste}", nomPropre); + return this.RedirectToAction("Index", "Accueil"); } + var viewModel = new ArtisteDetailsViewModel { IdArtiste = artiste.IdArtiste, Nom = artiste.Nom, Biographie = artiste.Biographie, - // On effectue le groupement ici une bonne fois pour toutes AlbumsGroupes = artiste.Titres - .OrderBy(t => t.Libelle) - .GroupBy(t => t.Album) - .OrderBy(g => g.Key), + .OrderBy(t => t.Libelle) + .GroupBy(t => t.Album) + .OrderBy(g => g.Key), }; this.logger.LogInformation("Artiste trouvé : {NomArtiste}", nom); - - return View(viewModel); + return this.View(viewModel); } } }