|
| 1 | +name: Resolution time benchmark |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + resolution-time: |
| 8 | + if: github.event.pull_request.head.repo.full_name == github.repository |
| 9 | + permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Install pnpm |
| 15 | + uses: pnpm/action-setup@v4 |
| 16 | + with: |
| 17 | + version: 10.27.0 |
| 18 | + run_install: false |
| 19 | + |
| 20 | + - name: Checkout PR branch |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + path: pr-branch |
| 24 | + |
| 25 | + - name: Checkout target branch |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + path: target-branch |
| 29 | + ref: ${{ github.base_ref }} |
| 30 | + |
| 31 | + - name: Checkout latest release |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + path: release-branch |
| 35 | + ref: release |
| 36 | + |
| 37 | + - name: Copy resolution-time app to release checkout |
| 38 | + run: | |
| 39 | + if [ ! -d release-branch/apps/resolution-time ]; then |
| 40 | + cp -r target-branch/apps/resolution-time release-branch/apps/resolution-time |
| 41 | + echo "Copied resolution-time app from target branch to release checkout" |
| 42 | + else |
| 43 | + echo "resolution-time app already exists in release checkout" |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Set up Node.js |
| 47 | + uses: actions/setup-node@v4 |
| 48 | + with: |
| 49 | + node-version: 24.x |
| 50 | + cache: 'pnpm' |
| 51 | + cache-dependency-path: | |
| 52 | + pr-branch/pnpm-lock.yaml |
| 53 | + target-branch/pnpm-lock.yaml |
| 54 | + release-branch/pnpm-lock.yaml |
| 55 | +
|
| 56 | + - name: Install dependencies (PR branch) |
| 57 | + working-directory: pr-branch |
| 58 | + run: pnpm install --frozen-lockfile |
| 59 | + |
| 60 | + - name: Install dependencies (target branch) |
| 61 | + working-directory: target-branch |
| 62 | + run: pnpm install --frozen-lockfile |
| 63 | + |
| 64 | + - name: Install dependencies (release branch) |
| 65 | + working-directory: release-branch |
| 66 | + run: pnpm install --no-frozen-lockfile |
| 67 | + |
| 68 | + - name: Run benchmark (PR branch) |
| 69 | + working-directory: pr-branch |
| 70 | + run: pnpm --filter resolution-time resolution-time |
| 71 | + |
| 72 | + - name: Run benchmark (target branch) |
| 73 | + working-directory: target-branch |
| 74 | + run: pnpm --filter resolution-time resolution-time |
| 75 | + |
| 76 | + - name: Run benchmark (release branch) |
| 77 | + working-directory: release-branch |
| 78 | + run: pnpm --filter resolution-time resolution-time |
| 79 | + |
| 80 | + - name: Generate chart (random) |
| 81 | + run: | |
| 82 | + node pr-branch/apps/resolution-time/generateChart.ts \ |
| 83 | + --input "PR:pr-branch/apps/resolution-time/results-random.json" \ |
| 84 | + --input "main:target-branch/apps/resolution-time/results-random.json" \ |
| 85 | + --input "release:release-branch/apps/resolution-time/results-random.json" \ |
| 86 | + --title "Random Branching" \ |
| 87 | + --xAxisTitle "max depth" \ |
| 88 | + --yAxisTitle "time (ms)" \ |
| 89 | + --output chart-random.md |
| 90 | +
|
| 91 | + - name: Generate chart (linear) |
| 92 | + run: | |
| 93 | + node pr-branch/apps/resolution-time/generateChart.ts \ |
| 94 | + --input "PR:pr-branch/apps/resolution-time/results-linear-recursion.json" \ |
| 95 | + --input "main:target-branch/apps/resolution-time/results-linear-recursion.json" \ |
| 96 | + --input "release:release-branch/apps/resolution-time/results-linear-recursion.json" \ |
| 97 | + --title "Linear Recursion" \ |
| 98 | + --xAxisTitle "max depth" \ |
| 99 | + --yAxisTitle "time (ms)" \ |
| 100 | + --output chart-linear.md |
| 101 | +
|
| 102 | + - name: Generate chart (max depth) |
| 103 | + run: | |
| 104 | + node pr-branch/apps/resolution-time/generateChart.ts \ |
| 105 | + --input "PR:pr-branch/apps/resolution-time/results-max-depth.json" \ |
| 106 | + --input "main:target-branch/apps/resolution-time/results-max-depth.json" \ |
| 107 | + --input "release:release-branch/apps/resolution-time/results-max-depth.json" \ |
| 108 | + --title "Full Tree" \ |
| 109 | + --xAxisTitle "max depth" \ |
| 110 | + --yAxisTitle "time (ms)" \ |
| 111 | + --output chart-max-depth.md |
| 112 | +
|
| 113 | + - name: Prepare comment |
| 114 | + run: | |
| 115 | + { |
| 116 | + echo "## Resolution Time Benchmark" |
| 117 | + echo "" |
| 118 | + cat chart-random.md |
| 119 | + echo "" |
| 120 | + cat chart-linear.md |
| 121 | + echo "" |
| 122 | + cat chart-max-depth.md |
| 123 | + } > comparison.md |
| 124 | +
|
| 125 | + - name: Comment PR with results |
| 126 | + uses: actions/github-script@v7 |
| 127 | + with: |
| 128 | + script: | |
| 129 | + const fs = require('fs'); |
| 130 | + const comparison = fs.readFileSync('comparison.md', 'utf8'); |
| 131 | +
|
| 132 | + const botCommentIdentifier = '<!-- resolution-time-bot-comment -->'; |
| 133 | +
|
| 134 | + async function findBotComment(issueNumber) { |
| 135 | + if (!issueNumber) return null; |
| 136 | + const comments = await github.rest.issues.listComments({ |
| 137 | + owner: context.repo.owner, |
| 138 | + repo: context.repo.repo, |
| 139 | + issue_number: issueNumber, |
| 140 | + }); |
| 141 | + return comments.data.find((comment) => |
| 142 | + comment.body.includes(botCommentIdentifier) |
| 143 | + ); |
| 144 | + } |
| 145 | +
|
| 146 | + async function createOrUpdateComment(issueNumber) { |
| 147 | + if (!issueNumber) { |
| 148 | + console.log('No issue number provided. Cannot post or update comment.'); |
| 149 | + return; |
| 150 | + } |
| 151 | +
|
| 152 | + const existingComment = await findBotComment(issueNumber); |
| 153 | + if (existingComment) { |
| 154 | + await github.rest.issues.updateComment({ |
| 155 | + ...context.repo, |
| 156 | + comment_id: existingComment.id, |
| 157 | + body: botCommentIdentifier + '\n' + comparison, |
| 158 | + }); |
| 159 | + } else { |
| 160 | + await github.rest.issues.createComment({ |
| 161 | + ...context.repo, |
| 162 | + issue_number: issueNumber, |
| 163 | + body: botCommentIdentifier + '\n' + comparison, |
| 164 | + }); |
| 165 | + } |
| 166 | + } |
| 167 | +
|
| 168 | + const issueNumber = context.issue.number; |
| 169 | + if (!issueNumber) { |
| 170 | + console.log('No issue number found in context. Skipping comment.'); |
| 171 | + } else { |
| 172 | + await createOrUpdateComment(issueNumber); |
| 173 | + } |
| 174 | + await core.summary |
| 175 | + .addRaw(comparison) |
| 176 | + .write(); |
0 commit comments