feat: ajouter un flux de travail et un script de test pour la vérification des performances des points d’accès PR
This commit is contained in:
132
.gitea/workflows/pr-endpoint-check.yml
Normal file
132
.gitea/workflows/pr-endpoint-check.yml
Normal file
@@ -0,0 +1,132 @@
|
||||
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:
|
||||
# ─────────────────────────────────────────────
|
||||
# 1. Checkout code
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 2. Setup .NET 10
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Setup .NET 10
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "10.0.x"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 3. Restore & Build
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore Webzine.sln
|
||||
|
||||
- name: Build solution
|
||||
run: dotnet build Webzine.sln --no-restore --configuration Release
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 4. Run unit tests (entity tests)
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Run unit tests
|
||||
run: |
|
||||
dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \
|
||||
--no-build \
|
||||
--configuration Release \
|
||||
--logger "console;verbosity=normal"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 5. Start the web application in background
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Start Webzine application
|
||||
run: |
|
||||
dotnet run \
|
||||
--project Webzine.WebApplication/Webzine.WebApplication.csproj \
|
||||
--configuration Release \
|
||||
--no-build \
|
||||
-- --urls "http://localhost:5038" &
|
||||
|
||||
echo "Waiting for application to start..."
|
||||
timeout 60 bash -c '
|
||||
until curl -sf http://localhost:5038 > /dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
'
|
||||
echo "Application is ready!"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 6. Run endpoint performance tests
|
||||
# ─────────────────────────────────────────────
|
||||
- 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"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 7. Post report as PR comment
|
||||
# ─────────────────────────────────────────────
|
||||
- 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 "No report generated.")
|
||||
FAILED_COUNT="${{ steps.perf_test.outputs.failed }}"
|
||||
|
||||
if [ "${FAILED_COUNT:-0}" -gt 0 ]; then
|
||||
HEADER="## ❌ Performance Check FAILED"
|
||||
INTRO="${FAILED_COUNT} endpoint(s) exceeded 1 second or returned a server error."
|
||||
else
|
||||
HEADER="## ✅ Performance Check PASSED"
|
||||
INTRO="All endpoints responded in under 1 second."
|
||||
fi
|
||||
|
||||
BODY=$(cat <<EOF
|
||||
$HEADER
|
||||
|
||||
$INTRO
|
||||
|
||||
\`\`\`
|
||||
$REPORT_CONTENT
|
||||
\`\`\`
|
||||
|
||||
> Threshold: **1000ms** | Checked by the **PR Endpoint Performance** workflow.
|
||||
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"
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# 8. Fail the job if any endpoint failed
|
||||
# ─────────────────────────────────────────────
|
||||
- name: Enforce performance gate
|
||||
run: |
|
||||
FAILED="${{ steps.perf_test.outputs.failed }}"
|
||||
if [ "${FAILED:-0}" -gt 0 ]; then
|
||||
echo "❌ PR REJECTED: ${FAILED} endpoint(s) failed the 1-second threshold."
|
||||
echo " Fix the slow/failing endpoints listed above before merging."
|
||||
exit 1
|
||||
else
|
||||
echo "✅ All endpoints passed the performance gate."
|
||||
fi
|
||||
Reference in New Issue
Block a user