Merge pull request 'j2/test/pr' (#128) from j2/test/pr into dev
Reviewed-on: https://10.4.0.131/gitea/DI1-P4-E1/Webzine/pulls/128 Reviewed-by: j.vetu <josephine.vetu@diiage.org>
This commit is contained in:
@@ -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é ==="
|
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
name: PR Endpoint Performance Check
|
name: PR Endpoint Performance Check
|
||||||
|
|
||||||
on:
|
on: [pull_request]
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
endpoint-performance-check:
|
endpoint-performance-check:
|
||||||
@@ -13,42 +8,41 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Récupération du code source
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Checkout PR branch
|
- name: Checkout PR branch
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
- name: Configure appsettings for CI
|
||||||
# Installation de .NET 10
|
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
|
- name: Setup .NET 10
|
||||||
uses: actions/setup-dotnet@v4
|
uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: "10.0.x"
|
dotnet-version: "10.0.x"
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Restauration des dépendances et compilation
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
run: dotnet restore Webzine.sln
|
run: dotnet restore Webzine.sln
|
||||||
|
|
||||||
- name: Build solution
|
- name: Build solution
|
||||||
run: dotnet build Webzine.sln --no-restore --configuration Release
|
run: dotnet build Webzine.sln --no-restore --configuration Release
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Exécution des tests unitaires (entités)
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: |
|
run: |
|
||||||
dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \
|
dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \
|
||||||
--no-build \
|
--no-build \
|
||||||
--configuration Release \
|
--configuration Release
|
||||||
--logger "console;verbosity=normal"
|
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Démarrage de l'application web en arrière-plan
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Start Webzine application
|
- name: Start Webzine application
|
||||||
run: |
|
run: |
|
||||||
dotnet run \
|
dotnet run \
|
||||||
@@ -63,51 +57,83 @@ jobs:
|
|||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
'
|
'
|
||||||
echo "Application prête !"
|
echo "Application prête!"
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Exécution des tests de performance des endpoints
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Test endpoint response times
|
- name: Test endpoint response times
|
||||||
id: perf_test
|
id: perf_test
|
||||||
run: |
|
run: |
|
||||||
chmod +x scripts/test-endpoints.sh
|
chmod +x scripts/test-endpoints.sh
|
||||||
bash scripts/test-endpoints.sh http://localhost:5038 1000 || true
|
bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt
|
||||||
FAIL_COUNT=$(grep -c "^\[FAIL\]\|^\[SLOW\]" /tmp/webzine_endpoint_report.txt || echo 0)
|
EXIT_CODE=${PIPESTATUS[0]}
|
||||||
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
|
|
||||||
|
# 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
|
- name: Post performance report as PR comment
|
||||||
if: always()
|
if: always() # Always post comment, even on failure
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||||
REPO: ${{ gitea.repository }}
|
REPO: ${{ gitea.repository }}
|
||||||
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
||||||
run: |
|
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 }}"
|
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
|
||||||
|
SLOW_COUNT="${{ steps.perf_test.outputs.slow }}"
|
||||||
|
|
||||||
if [ "${FAILED_COUNT:-0}" -gt 0 ]; then
|
# Determine if the check passed or failed
|
||||||
HEADER="## ❌ Vérification des performances ÉCHOUÉE"
|
if [ "$FAILED_COUNT" -gt 0 ] || [ "$SLOW_COUNT" -gt 0 ]; then
|
||||||
INTRO="${FAILED_COUNT} endpoint(s) ont dépassé 1 seconde ou retourné une erreur serveur."
|
STATUS_HEADER="❌ **PERFORMANCE CHECK FAILED**"
|
||||||
|
STATUS_ICON="❌"
|
||||||
else
|
else
|
||||||
HEADER="## ✅ Vérification des performances RÉUSSIE"
|
STATUS_HEADER="✅ **PERFORMANCE CHECK PASSED**"
|
||||||
INTRO="Tous les endpoints ont répondu en moins d'une seconde."
|
STATUS_ICON="✅"
|
||||||
fi
|
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 <<EOF
|
BODY=$(cat <<EOF
|
||||||
$HEADER
|
$STATUS_HEADER
|
||||||
|
|
||||||
$INTRO
|
$FORMATTED_REPORT
|
||||||
|
|
||||||
\`\`\`
|
---
|
||||||
$REPORT_CONTENT
|
**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
|
||||||
|
|
||||||
> Seuil : **1000ms** | Vérifié par le workflow **PR Endpoint Performance**.
|
**Vérifié par**: Workflow PR Endpoint Performance
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,16 +143,8 @@ jobs:
|
|||||||
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \
|
-d "$(jq -n --arg body "$BODY" '{body: $body}')" \
|
||||||
"$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments"
|
"$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments"
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
- name: Fail job if performance issues detected
|
||||||
# Blocage de la PR si un endpoint a échoué
|
if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Enforce performance gate
|
|
||||||
run: |
|
run: |
|
||||||
FAILED="${{ steps.perf_test.outputs.failed }}"
|
echo "❌ Job failed due to performance issues"
|
||||||
if [ "${FAILED:-0}" -gt 0 ]; then
|
exit 1
|
||||||
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
|
|
||||||
@@ -103,12 +103,6 @@ namespace Webzine.Repository
|
|||||||
.Include(a => a.Titres)
|
.Include(a => a.Titres)
|
||||||
.FirstOrDefault(a => a.Nom == nom);
|
.FirstOrDefault(a => a.Nom == nom);
|
||||||
|
|
||||||
if (artiste == null)
|
|
||||||
{
|
|
||||||
this.logger.LogWarning("Pas d'artiste au nom {Nom}", nom);
|
|
||||||
artiste = new Artiste();
|
|
||||||
}
|
|
||||||
|
|
||||||
return artiste;
|
return artiste;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
if (string.IsNullOrEmpty(nom))
|
if (string.IsNullOrEmpty(nom))
|
||||||
{
|
{
|
||||||
this.logger.LogWarning("Nom de l'artiste manquant dans la requête.");
|
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
|
// On transforme "fatal-bazooka" en "Fatal Bazooka" pour la factory
|
||||||
@@ -46,26 +46,26 @@
|
|||||||
// On appelle la factory pour obtenir l'artiste unique
|
// On appelle la factory pour obtenir l'artiste unique
|
||||||
var artiste = this._artisteRepository.FindByName(nomPropre);
|
var artiste = this._artisteRepository.FindByName(nomPropre);
|
||||||
|
|
||||||
|
// Check if artiste was found
|
||||||
if (artiste == null)
|
if (artiste == null)
|
||||||
{
|
{
|
||||||
this.logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
|
this.logger.LogWarning("Artiste non trouvé avec le nom : {NomArtiste}", nomPropre);
|
||||||
return RedirectToAction("Index");
|
return this.RedirectToAction("Index", "Accueil");
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = new ArtisteDetailsViewModel
|
var viewModel = new ArtisteDetailsViewModel
|
||||||
{
|
{
|
||||||
IdArtiste = artiste.IdArtiste,
|
IdArtiste = artiste.IdArtiste,
|
||||||
Nom = artiste.Nom,
|
Nom = artiste.Nom,
|
||||||
Biographie = artiste.Biographie,
|
Biographie = artiste.Biographie,
|
||||||
// On effectue le groupement ici une bonne fois pour toutes
|
|
||||||
AlbumsGroupes = artiste.Titres
|
AlbumsGroupes = artiste.Titres
|
||||||
.OrderBy(t => t.Libelle)
|
.OrderBy(t => t.Libelle)
|
||||||
.GroupBy(t => t.Album)
|
.GroupBy(t => t.Album)
|
||||||
.OrderBy(g => g.Key),
|
.OrderBy(g => g.Key),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
|
this.logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
|
||||||
|
return this.View(viewModel);
|
||||||
return View(viewModel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user