|
| 1 | +name: Provider Benchmarks |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "packages/disco/lib/**" |
| 7 | + - "packages/disco/benchmark/**" |
| 8 | + - ".github/workflows/benchmark.yaml" |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + - dev |
| 13 | + paths: |
| 14 | + - "packages/disco/lib/**" |
| 15 | + - "packages/disco/benchmark/**" |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +jobs: |
| 19 | + benchmark: |
| 20 | + name: Run Provider Benchmarks |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + pull-requests: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Setup Flutter |
| 31 | + uses: subosito/flutter-action@v2.18.0 |
| 32 | + with: |
| 33 | + channel: "stable" |
| 34 | + cache: true |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: flutter pub get |
| 38 | + working-directory: packages/disco |
| 39 | + |
| 40 | + - name: Run benchmarks (Debug Mode - Worst Case) |
| 41 | + working-directory: packages/disco |
| 42 | + run: | |
| 43 | + # Run benchmark, it will generate benchmark_results.md automatically |
| 44 | + flutter test benchmark/provider_benchmark.dart |
| 45 | +
|
| 46 | + - name: Upload benchmark results |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: benchmark-results |
| 50 | + path: packages/disco/benchmark_results.md |
| 51 | + |
| 52 | + - name: Update README with benchmark results |
| 53 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') |
| 54 | + run: | |
| 55 | + # Read benchmark results |
| 56 | + BENCHMARK_CONTENT=$(cat packages/disco/benchmark_results.md) |
| 57 | +
|
| 58 | + # Check if README already has a Benchmark section |
| 59 | + if grep -q "^## Benchmark" packages/disco/README.md; then |
| 60 | + # Remove everything from ## Benchmark to the end |
| 61 | + sed -i '/^## Benchmark/,$d' packages/disco/README.md |
| 62 | + fi |
| 63 | +
|
| 64 | + # Add benchmark section at the end |
| 65 | + echo "" >> packages/disco/README.md |
| 66 | + echo "## Benchmark" >> packages/disco/README.md |
| 67 | + echo "" >> packages/disco/README.md |
| 68 | + echo "$BENCHMARK_CONTENT" >> packages/disco/README.md |
| 69 | +
|
| 70 | + - name: Commit benchmark results to README |
| 71 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') |
| 72 | + run: | |
| 73 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 74 | + git config --local user.name "github-actions[bot]" |
| 75 | + git add packages/disco/README.md |
| 76 | + if git diff --staged --quiet; then |
| 77 | + echo "No changes to commit" |
| 78 | + else |
| 79 | + git commit -m "chore: update benchmark results in README [skip ci]" |
| 80 | + git push |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Comment PR with results |
| 84 | + if: github.event_name == 'pull_request' |
| 85 | + uses: actions/github-script@v7 |
| 86 | + with: |
| 87 | + script: | |
| 88 | + const fs = require('fs'); |
| 89 | + const results = fs.readFileSync('packages/disco/benchmark_results.md', 'utf8'); |
| 90 | +
|
| 91 | + // Check if we already commented |
| 92 | + const comments = await github.rest.issues.listComments({ |
| 93 | + owner: context.repo.owner, |
| 94 | + repo: context.repo.repo, |
| 95 | + issue_number: context.issue.number, |
| 96 | + }); |
| 97 | +
|
| 98 | + const botComment = comments.data.find(comment => |
| 99 | + comment.user.type === 'Bot' && |
| 100 | + comment.body.includes('Provider Benchmark Results') |
| 101 | + ); |
| 102 | +
|
| 103 | + if (botComment) { |
| 104 | + // Update existing comment |
| 105 | + await github.rest.issues.updateComment({ |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + comment_id: botComment.id, |
| 109 | + body: results |
| 110 | + }); |
| 111 | + } else { |
| 112 | + // Create new comment |
| 113 | + await github.rest.issues.createComment({ |
| 114 | + issue_number: context.issue.number, |
| 115 | + owner: context.repo.owner, |
| 116 | + repo: context.repo.repo, |
| 117 | + body: results |
| 118 | + }); |
| 119 | + } |
| 120 | +
|
| 121 | + - name: Display results |
| 122 | + run: cat packages/disco/benchmark_results.md |
0 commit comments