feat: améliorer le workflow de test de performance des endpoints
This commit is contained in:
@@ -8,32 +8,20 @@ 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
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Installation de .NET 10
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- 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 \
|
||||||
@@ -41,9 +29,6 @@ jobs:
|
|||||||
--configuration Release \
|
--configuration Release \
|
||||||
--logger "console;verbosity=normal"
|
--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 \
|
||||||
@@ -60,20 +45,21 @@ jobs:
|
|||||||
'
|
'
|
||||||
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]}
|
||||||
|
|
||||||
|
FAIL_COUNT=$(grep -c "^\[FAIL\]\|^\[SLOW\]" /tmp/webzine_endpoint_output.txt || echo 0)
|
||||||
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
|
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
cat /tmp/webzine_endpoint_output.txt > /tmp/webzine_endpoint_report.txt
|
||||||
|
|
||||||
|
exit $EXIT_CODE
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# 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()
|
||||||
env:
|
env:
|
||||||
@@ -84,43 +70,64 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
REPORT_CONTENT=$(cat /tmp/webzine_endpoint_report.txt 2>/dev/null || echo "Aucun rapport généré.")
|
REPORT_CONTENT=$(cat /tmp/webzine_endpoint_report.txt 2>/dev/null || echo "Aucun rapport généré.")
|
||||||
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
|
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
|
||||||
|
|
||||||
|
REPORT_CONTENT_ESCAPED=$(echo "$REPORT_CONTENT" | sed 's/`/\\`/g' | sed 's/\\/\\\\/g')
|
||||||
|
|
||||||
if [ "${FAILED_COUNT:-0}" -gt 0 ]; then
|
if [ "${FAILED_COUNT:-0}" -gt 0 ]; then
|
||||||
HEADER="## ❌ Vérification des performances ÉCHOUÉE"
|
HEADER="## ❌ Vérification des performances ÉCHOUÉE"
|
||||||
INTRO="${FAILED_COUNT} endpoint(s) ont dépassé 1 seconde ou retourné une erreur serveur."
|
INTRO="${FAILED_COUNT} endpoint(s) ont dépassé 1 seconde ou retourné une erreur serveur."
|
||||||
|
STATUS="ÉCHEC"
|
||||||
else
|
else
|
||||||
HEADER="## ✅ Vérification des performances RÉUSSIE"
|
HEADER="## ✅ Vérification des performances RÉUSSIE"
|
||||||
INTRO="Tous les endpoints ont répondu en moins d'une seconde."
|
INTRO="Tous les endpoints ont répondu en moins d'une seconde."
|
||||||
|
STATUS="SUCCÈS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BODY=$(cat <<EOF
|
BODY=$(cat <<EOF
|
||||||
$HEADER
|
$HEADER
|
||||||
|
|
||||||
$INTRO
|
$INTRO
|
||||||
|
|
||||||
|
### Rapport complet des tests :
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
$REPORT_CONTENT
|
$REPORT_CONTENT_ESCAPED
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
> Seuil : **1000ms** | Vérifié par le workflow **PR Endpoint Performance**.
|
---
|
||||||
|
**Statut**: $STATUS
|
||||||
|
**Seuil**: 1000ms
|
||||||
|
**Vérifié par**: Workflow PR Endpoint Performance
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-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"
|
||||||
|
|
||||||
|
mkdir -p /tmp/artifacts
|
||||||
|
cp /tmp/webzine_endpoint_report.txt /tmp/artifacts/performance-report.txt
|
||||||
|
|
||||||
|
- name: Upload performance report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: performance-report
|
||||||
|
path: /tmp/artifacts/
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
# Blocage de la PR si un endpoint a échoué
|
|
||||||
# ─────────────────────────────────────────────
|
|
||||||
- name: Enforce performance gate
|
- name: Enforce performance gate
|
||||||
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
FAILED="${{ steps.perf_test.outputs.failed }}"
|
FAILED="${{ steps.perf_test.outputs.failed }}"
|
||||||
if [ "${FAILED:-0}" -gt 0 ]; then
|
if [ "${FAILED:-0}" -gt 0 ]; then
|
||||||
echo "❌ PR REJETÉE : ${FAILED} endpoint(s) n'ont pas respecté le seuil d'une seconde."
|
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."
|
echo " Corrigez les endpoints lents ou en erreur avant de fusionner."
|
||||||
|
echo ""
|
||||||
|
echo "Résumé des problèmes :"
|
||||||
|
grep -E "^\[(FAIL|SLOW)\]" /tmp/webzine_endpoint_report.txt || echo " (aucun détail disponible)"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "✅ Tous les endpoints ont passé le contrôle de performance."
|
echo "✅ Tous les endpoints ont passé le contrôle de performance."
|
||||||
|
|||||||
Reference in New Issue
Block a user