size-comment #205
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
| name: size-comment | |
| on: | |
| workflow_run: | |
| workflows: [size] | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| comment: | |
| # Only run if the build workflow succeeded | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version: latest | |
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 | |
| with: | |
| sparse-checkout: scripts/parse-sizes.ts | |
| sparse-checkout-cone-mode: false | |
| - name: ⏬ Download artifacts from workflow run | |
| uses: actions/download-artifact@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| path: . | |
| - name: 🔍 Get PR number from artifact | |
| id: pr | |
| run: | | |
| if [ -f pr-number/pr-number.txt ]; then | |
| PR_NUMBER=$(cat pr-number/pr-number.txt) | |
| echo "result=$PR_NUMBER" >> $GITHUB_OUTPUT | |
| echo "Found PR number: $PR_NUMBER" | |
| else | |
| echo "PR number file not found" | |
| echo "result=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: 📊 Generate size comparison | |
| id: sizes | |
| run: | | |
| COMMENT=$(node scripts/parse-sizes.ts nuxi nuxt-cli create-nuxt) | |
| echo "comment<<EOF" >> $GITHUB_OUTPUT | |
| echo "$COMMENT" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 💬 Post or update comment | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const prNumber = ${{ steps.pr.outputs.result }}; | |
| const commentBody = `${{ steps.sizes.outputs.comment }}`; | |
| // Find existing comment | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('Bundle Size Comparison') | |
| ); | |
| if (botComment) { | |
| console.log(`Updating existing comment ${botComment.id}`); | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| } else { | |
| console.log('Creating new comment'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: commentBody | |
| }); | |
| } |