132 lines
6.1 KiB
YAML
132 lines
6.1 KiB
YAML
name: PR Endpoint Performance Check
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
- develop
|
|
|
|
jobs:
|
|
endpoint-performance-check:
|
|
name: Test All Endpoints (< 1s)
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# ─────────────────────────────────────────────
|
|
# Récupération du code source
|
|
# ─────────────────────────────────────────────
|
|
- name: Checkout PR branch
|
|
uses: actions/checkout@v4
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Installation de .NET 10
|
|
# ─────────────────────────────────────────────
|
|
- 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"
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Démarrage de l'application web en arrière-plan
|
|
# ─────────────────────────────────────────────
|
|
- name: Start Webzine application
|
|
run: |
|
|
dotnet run \
|
|
--project Webzine.WebApplication/Webzine.WebApplication.csproj \
|
|
--configuration Release \
|
|
--no-build \
|
|
-- --urls "http://localhost:5038" &
|
|
|
|
echo "Attente du démarrage de l'application..."
|
|
timeout 60 bash -c '
|
|
until curl -sf http://localhost:5038 > /dev/null 2>&1; do
|
|
sleep 1
|
|
done
|
|
'
|
|
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)
|
|
echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT"
|
|
|
|
# ─────────────────────────────────────────────
|
|
# Publication du rapport en commentaire de PR
|
|
# ─────────────────────────────────────────────
|
|
- name: Post performance report as PR comment
|
|
if: always()
|
|
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é.")
|
|
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."
|
|
else
|
|
HEADER="## ✅ Vérification des performances RÉUSSIE"
|
|
INTRO="Tous les endpoints ont répondu en moins d'une seconde."
|
|
fi
|
|
|
|
BODY=$(cat <<EOF
|
|
$HEADER
|
|
|
|
$INTRO
|
|
|
|
\`\`\`
|
|
$REPORT_CONTENT
|
|
\`\`\`
|
|
|
|
> Seuil : **1000ms** | Vérifié par le 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
|
|
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 |