From b8efa61e08dace42f4cc022e59ab5e263b197815 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Fri, 27 Mar 2026 13:29:18 +0100 Subject: [PATCH] fix: enhance performance check to account for slow endpoints and improve reporting --- .gitea/workflows/pr-endpoint-check.yml | 48 +++++++++++++++++++------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index 1975e45..427f687 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -57,7 +57,7 @@ jobs: sleep 1 done ' - echo "Application prête !" + echo "Application prête!" - name: Test endpoint response times id: perf_test @@ -66,20 +66,23 @@ jobs: bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt EXIT_CODE=${PIPESTATUS[0]} - # Count failures (but not slow endpoints as failures) + # 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" - # Only fail if there are actual failures - if [ $FAIL_COUNT -gt 0 ]; then + # É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)" - 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 }} @@ -88,12 +91,21 @@ jobs: run: | RAW_REPORT=$(cat /tmp/webzine_endpoint_output.txt 2>/dev/null || echo "Aucune sortie capturée.") FAILED_COUNT="${{ steps.perf_test.outputs.failed }}" + SLOW_COUNT="${{ steps.perf_test.outputs.slow }}" - # Convertir le rapport ANSI en Markdown avec couleurs - # Supprimer d'abord les codes ANSI pour le traitement + # 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 + 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') - # Générer le rapport formaté en Markdown avec couleurs + # Generate formatted report FORMATTED_REPORT=$(echo "$CLEAN_REPORT" | sed \ -e 's/^\[OK\] /✅ /' \ -e 's/^\[LENT\] /⚠️ /' \ @@ -105,16 +117,22 @@ jobs: -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**/' \ - -e 's/^╔\(.*\)╗$/```\n╔\1╗/' \ - -e 's/^╚\(.*\)╝$/╚\1╝\n```/') + -e 's/^\(La PR doit.*\)$/\n**❌ \1**/') BODY=$(cat </dev/null || echo 0) + - ⚠️ Endpoints lents (>1000ms): $SLOW_COUNT + - ❌ Endpoints en échec: $FAILED_COUNT + **Vérifié par**: Workflow PR Endpoint Performance EOF ) @@ -123,4 +141,10 @@ jobs: -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" \ No newline at end of file + "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" + + - name: Fail job if performance issues detected + if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0 + run: | + echo "❌ Job failed due to performance issues" + exit 1 \ No newline at end of file