146 lines
5.0 KiB
YAML
146 lines
5.0 KiB
YAML
name: PR Endpoint Performance Check
|
|
|
|
on: [pull_request]
|
|
|
|
jobs:
|
|
endpoint-performance-check:
|
|
name: Test All Endpoints (< 1s)
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout PR branch
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Configure appsettings for CI
|
|
run: |
|
|
APPSETTINGS_PATH="Webzine.WebApplication/appsettings.json"
|
|
cp $APPSETTINGS_PATH $APPSETTINGS_PATH.bak
|
|
jq '.UseDatabase = true | .IsSQLite = true' $APPSETTINGS_PATH > $APPSETTINGS_PATH.tmp
|
|
mv $APPSETTINGS_PATH.tmp $APPSETTINGS_PATH
|
|
echo "Updated appsettings.json:"
|
|
cat $APPSETTINGS_PATH
|
|
|
|
- name: Cache .NET SDK
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.dotnet
|
|
/usr/share/dotnet
|
|
key: ${{ runner.os }}-dotnet-10.0.x
|
|
|
|
- name: Cache NuGet packages
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.nuget/packages
|
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.sln') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nuget-
|
|
|
|
- name: Setup .NET 10
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: "10.0.x"
|
|
|
|
- name: Restore dependencies
|
|
run: dotnet restore Webzine.sln
|
|
|
|
- name: Build solution
|
|
run: dotnet build Webzine.sln --no-restore --configuration Release
|
|
|
|
- name: Run unit tests
|
|
run: |
|
|
dotnet test Webzine.Entity.Tests/Webzine.Entity.Tests.csproj \
|
|
--no-build \
|
|
--configuration Release
|
|
|
|
- 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!"
|
|
|
|
- name: Test endpoint response times
|
|
id: perf_test
|
|
run: |
|
|
chmod +x scripts/test-endpoints.sh
|
|
bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt
|
|
EXIT_CODE=${PIPESTATUS[0]}
|
|
|
|
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"
|
|
|
|
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()
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
|
REPO: ${{ gitea.repository }}
|
|
PR_NUMBER: ${{ gitea.event.pull_request.number }}
|
|
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 }}"
|
|
|
|
if [ "$FAILED_COUNT" -gt 0 ] || [ "$SLOW_COUNT" -gt 0 ]; then
|
|
STATUS_HEADER="❌ **PERFORMANCE CHECK FAILED**"
|
|
else
|
|
STATUS_HEADER="✅ **PERFORMANCE CHECK PASSED**"
|
|
fi
|
|
|
|
CLEAN_REPORT=$(echo "$RAW_REPORT" | sed 's/\x1b\[[0-9;]*m//g')
|
|
|
|
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
|
|
$STATUS_HEADER
|
|
|
|
$FORMATTED_REPORT
|
|
|
|
**Vérifié par**: 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"
|
|
|
|
- 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 |