feat: add --use-server-token-count CLI option to use server-reported … #108
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: "PR Install Instructions" | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| - synchronize # Triggers when new commits are pushed to the PR | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR number to comment on' | |
| required: true | |
| type: number | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| comment-install-instructions: | |
| name: Comment with install instructions | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Post or update install instructions | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| // Get PR number and commit SHA based on trigger type | |
| let prNumber, commitSha; | |
| if (context.eventName === 'workflow_dispatch') { | |
| // Manual trigger - fetch PR details | |
| prNumber = context.payload.inputs.pr_number; | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| commitSha = pr.head.sha; | |
| } else { | |
| // Automatic trigger on PR opened or synchronized | |
| prNumber = context.issue.number; | |
| commitSha = context.payload.pull_request.head.sha; | |
| } | |
| const commentIdentifier = '<!-- aiperf-pr-install-instructions -->'; | |
| const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; | |
| const commentBody = `${commentIdentifier} | |
| ### Try out this PR | |
| **Quick install:** | |
| \`\`\`bash | |
| pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@${commitSha} | |
| \`\`\` | |
| **Recommended with virtual environment (using [uv](https://docs.astral.sh/uv/)):** | |
| \`\`\`bash | |
| uv venv --python 3.12 && source .venv/bin/activate | |
| uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@${commitSha} | |
| \`\`\` | |
| --- | |
| _Last updated for commit: [\`${commitSha.substring(0, 7)}\`](${repoUrl}/commit/${commitSha}) • [Browse code](${repoUrl}/tree/${commitSha})_`; | |
| // Find existing comment from this bot | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes(commentIdentifier) | |
| ); | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| console.log('Updated existing comment with new commit SHA'); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| issue_number: prNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: commentBody | |
| }); | |
| console.log('Created new comment with commit SHA'); | |
| } |