WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

size-comment

size-comment #213

Workflow file for this run

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@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.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
});
}