55 branches :
66 - main
77 - main-version-*
8+ paths-ignore :
9+ - ' src/HotChocolate/AspNetCore/benchmarks/k6/performance-data.json'
810
911concurrency :
1012 group : ci-new-2-${{ github.event.pull_request.number }}
@@ -257,9 +259,170 @@ jobs:
257259 flags : unittests
258260 fail_ci_if_error : true
259261
262+ performance-tests :
263+ name : " Performance Tests"
264+ needs : check-changes
265+ if : needs.check-changes.outputs.src_changes == 'true' && github.event.pull_request.draft == false
266+ runs-on : ubuntu-latest
267+ permissions :
268+ contents : write
269+ pull-requests : write
270+
271+ steps :
272+ - name : Checkout PR code
273+ uses : actions/checkout@v4
274+ with :
275+ fetch-depth : 0
276+ show-progress : false
277+
278+ - name : Setup .NET
279+ uses : actions/setup-dotnet@v4
280+ with :
281+ dotnet-version : |
282+ 8.x
283+ 9.x
284+ 10.x
285+
286+ - name : Install k6
287+ run : |
288+ sudo gpg -k
289+ sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
290+ echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
291+ sudo apt-get update
292+ sudo apt-get install k6
293+
294+ - name : Install jq
295+ run : sudo apt-get install -y jq
296+
297+ - name : Restore dependencies
298+ run : dotnet restore src/HotChocolate/AspNetCore/benchmarks/k6/eShop.slnx
299+
300+ - name : Start AppHost and wait for readiness
301+ working-directory : src/HotChocolate/AspNetCore/benchmarks/k6/Catalog.AppHost
302+ run : |
303+ echo "Starting AppHost..."
304+ dotnet run > /tmp/apphost.log 2>&1 &
305+ APPHOST_PID=$!
306+ echo "APPHOST_PID=$APPHOST_PID" >> $GITHUB_ENV
307+
308+ echo "Waiting for server to be ready..."
309+ for i in {1..30}; do
310+ if curl -s -o /dev/null -w "%{http_code}" http://localhost:5224/graphql -X POST \
311+ -H "Content-Type: application/json" \
312+ -d '{"query": "{ __typename }"}' | grep -q "200"; then
313+ echo "Server is ready!"
314+ break
315+ fi
316+ echo "Waiting... ($i/30)"
317+ sleep 2
318+ done
319+
320+ - name : Run performance tests and collect data
321+ working-directory : src/HotChocolate/AspNetCore/benchmarks/k6
322+ run : |
323+ chmod +x run-and-collect.sh
324+ ./run-and-collect.sh performance-data-current.json
325+
326+ - name : Stop AppHost
327+ if : always()
328+ run : |
329+ if [ -n "$APPHOST_PID" ]; then
330+ kill $APPHOST_PID 2>/dev/null || true
331+ wait $APPHOST_PID 2>/dev/null || true
332+ fi
333+
334+ - name : Commit and push performance data to current branch
335+ working-directory : src/HotChocolate/AspNetCore/benchmarks/k6
336+ run : |
337+ # Copy the performance data to the tracked filename
338+ cp performance-data-current.json performance-data.json
339+
340+ # Configure git
341+ git config user.name "github-actions[bot]"
342+ git config user.email "github-actions[bot]@users.noreply.github.com"
343+
344+ # Add and commit the performance data
345+ git add performance-data.json
346+
347+ # Only commit if there are changes
348+ if ! git diff --staged --quiet; then
349+ git commit -m "Update performance data [skip ci]"
350+ git push origin HEAD:${{ github.head_ref }}
351+ else
352+ echo "No changes to performance data"
353+ fi
354+
355+ - name : Fetch baseline performance data from main
356+ run : |
357+ git fetch origin main:main
358+ if git show main:src/HotChocolate/AspNetCore/benchmarks/k6/performance-data.json > baseline-performance.json 2>/dev/null; then
359+ echo "Baseline data fetched successfully"
360+ else
361+ echo "No baseline data found on main branch"
362+ echo '{}' > baseline-performance.json
363+ fi
364+
365+ - name : Compare performance and generate report
366+ working-directory : src/HotChocolate/AspNetCore/benchmarks/k6
367+ run : |
368+ chmod +x compare-performance.sh
369+ ./compare-performance.sh performance-data-current.json ../../../../baseline-performance.json performance-report.md
370+
371+ - name : Comment PR with performance report
372+ uses : actions/github-script@v7
373+ with :
374+ github-token : ${{ secrets.GITHUB_TOKEN }}
375+ script : |
376+ const fs = require('fs');
377+ const reportPath = 'src/HotChocolate/AspNetCore/benchmarks/k6/performance-report.md';
378+
379+ let report;
380+ try {
381+ report = fs.readFileSync(reportPath, 'utf8');
382+ } catch (error) {
383+ console.error('Failed to read performance report:', error);
384+ return;
385+ }
386+
387+ // Add timestamp and commit info to the report
388+ const timestamp = new Date().toUTCString();
389+ const commitSha = context.sha.substring(0, 7);
390+ const runNumber = context.runNumber;
391+
392+ const commentBody = `${report}\n\n---\n*Run #${runNumber} • Commit ${commitSha} • ${timestamp}*`;
393+
394+ // Always create a new comment
395+ await github.rest.issues.createComment({
396+ owner: context.repo.owner,
397+ repo: context.repo.repo,
398+ issue_number: context.issue.number,
399+ body: commentBody,
400+ });
401+
402+ - name : Upload performance data as artifact
403+ uses : actions/upload-artifact@v4
404+ if : always()
405+ with :
406+ name : performance-data
407+ path : |
408+ src/HotChocolate/AspNetCore/benchmarks/k6/performance-data-current.json
409+ src/HotChocolate/AspNetCore/benchmarks/k6/performance-report.md
410+ /tmp/apphost.log
411+ retention-days : 30
412+
413+ - name : Check for performance regression
414+ working-directory : src/HotChocolate/AspNetCore/benchmarks/k6
415+ run : |
416+ # Fail the build if there's a significant performance regression
417+ if grep -q "⚠️ \*\*Performance regression detected" performance-report.md; then
418+ echo "::warning::Performance regression detected! Please review the performance report."
419+ # Uncomment the next line to fail the build on regression
420+ # exit 1
421+ fi
422+
260423 ci-status-check :
261424 name : " CI Status Check"
262- needs : [library-tests, website-tests]
425+ needs : [library-tests, website-tests, performance-tests ]
263426 if : always()
264427 runs-on : ubuntu-latest
265428 steps :
@@ -268,4 +431,5 @@ jobs:
268431 if : |
269432 always() &&
270433 (needs.library-tests.result == 'failure' ||
271- needs.website-tests.result == 'failure')
434+ needs.website-tests.result == 'failure' ||
435+ needs.performance-tests.result == 'failure')
0 commit comments