Skip to content

size-comment

size-comment #1115

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-slim
steps:
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: latest
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
sparse-checkout: scripts/parse-sizes.ts
sparse-checkout-cone-mode: false
persist-credentials: false
- name: ⏬ Download artifacts from workflow run
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
path: .
- name: 🔍 Get PR number from artifact
id: pr
if: false
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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
if: false
env:
PR_NUMBER: ${{ steps.pr.outputs.result }}
COMMENT_BODY: ${{ steps.sizes.outputs.comment }}
with:
script: |
const prNumber = Number(process.env.PR_NUMBER);
const commentBody = process.env.COMMENT_BODY;
// 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
});
}