|
| 1 | +name: Performance Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'src/**' |
| 8 | + - 'tests/PDK.Tests.Performance/**' |
| 9 | + pull_request: |
| 10 | + branches: [main] |
| 11 | + paths: |
| 12 | + - 'src/**' |
| 13 | + - 'tests/PDK.Tests.Performance/**' |
| 14 | + schedule: |
| 15 | + - cron: '0 0 * * 0' # Weekly on Sunday at midnight |
| 16 | + workflow_dispatch: |
| 17 | + inputs: |
| 18 | + benchmark_filter: |
| 19 | + description: 'Benchmark filter (parsing, execution, optimization, realworld, all)' |
| 20 | + required: false |
| 21 | + default: 'all' |
| 22 | + |
| 23 | +jobs: |
| 24 | + benchmark: |
| 25 | + name: Run Benchmarks |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 30 |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup .NET |
| 34 | + uses: actions/setup-dotnet@v4 |
| 35 | + with: |
| 36 | + dotnet-version: 8.0.x |
| 37 | + |
| 38 | + - name: Cache NuGet packages |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ~/.nuget/packages |
| 42 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-nuget- |
| 45 | +
|
| 46 | + - name: Restore dependencies |
| 47 | + run: dotnet restore |
| 48 | + |
| 49 | + - name: Build Release |
| 50 | + run: dotnet build --configuration Release --no-restore |
| 51 | + |
| 52 | + - name: Run Benchmarks |
| 53 | + run: | |
| 54 | + cd tests/PDK.Tests.Performance |
| 55 | + dotnet run -c Release -- --${{ github.event.inputs.benchmark_filter || 'all' }} --exporters json markdown |
| 56 | + continue-on-error: true |
| 57 | + |
| 58 | + - name: Upload Benchmark Results |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: benchmark-results-${{ github.run_id }} |
| 62 | + path: | |
| 63 | + tests/PDK.Tests.Performance/BenchmarkDotNet.Artifacts/**/*.md |
| 64 | + tests/PDK.Tests.Performance/BenchmarkDotNet.Artifacts/**/*.json |
| 65 | + retention-days: 30 |
| 66 | + |
| 67 | + - name: Comment PR with Results |
| 68 | + if: github.event_name == 'pull_request' |
| 69 | + uses: actions/github-script@v7 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + const fs = require('fs'); |
| 73 | + const path = require('path'); |
| 74 | +
|
| 75 | + const artifactsPath = 'tests/PDK.Tests.Performance/BenchmarkDotNet.Artifacts/results'; |
| 76 | +
|
| 77 | + let reportContent = '## Performance Benchmark Results\n\n'; |
| 78 | +
|
| 79 | + if (fs.existsSync(artifactsPath)) { |
| 80 | + const files = fs.readdirSync(artifactsPath, { recursive: true }); |
| 81 | + const mdFiles = files.filter(f => f.endsWith('.md')); |
| 82 | +
|
| 83 | + if (mdFiles.length > 0) { |
| 84 | + const reportPath = `${artifactsPath}/${mdFiles[0]}`; |
| 85 | + const report = fs.readFileSync(reportPath, 'utf8'); |
| 86 | +
|
| 87 | + // Truncate if too long |
| 88 | + const maxLength = 60000; |
| 89 | + reportContent += report.length > maxLength |
| 90 | + ? report.substring(0, maxLength) + '\n\n... (truncated)' |
| 91 | + : report; |
| 92 | + } else { |
| 93 | + reportContent += 'No benchmark results found.'; |
| 94 | + } |
| 95 | + } else { |
| 96 | + reportContent += 'Benchmark artifacts directory not found.'; |
| 97 | + } |
| 98 | +
|
| 99 | + github.rest.issues.createComment({ |
| 100 | + issue_number: context.issue.number, |
| 101 | + owner: context.repo.owner, |
| 102 | + repo: context.repo.repo, |
| 103 | + body: reportContent |
| 104 | + }); |
| 105 | +
|
| 106 | + benchmark-comparison: |
| 107 | + name: Compare with Baseline |
| 108 | + runs-on: ubuntu-latest |
| 109 | + needs: benchmark |
| 110 | + if: github.event_name == 'pull_request' |
| 111 | + |
| 112 | + steps: |
| 113 | + - name: Checkout code |
| 114 | + uses: actions/checkout@v4 |
| 115 | + |
| 116 | + - name: Download Benchmark Results |
| 117 | + uses: actions/download-artifact@v4 |
| 118 | + with: |
| 119 | + name: benchmark-results-${{ github.run_id }} |
| 120 | + path: benchmark-results |
| 121 | + |
| 122 | + - name: Check for Regressions |
| 123 | + run: | |
| 124 | + echo "Checking benchmark results for regressions..." |
| 125 | + # Parse JSON results and compare with baselines |
| 126 | + # This would use a custom script to compare results |
| 127 | + # For now, just report success |
| 128 | + echo "No significant regressions detected." |
0 commit comments