-
Notifications
You must be signed in to change notification settings - Fork 111
91 lines (80 loc) · 2.91 KB
/
size-comment.yml
File metadata and controls
91 lines (80 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: latest
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
sparse-checkout: scripts/parse-sizes.ts
sparse-checkout-cone-mode: 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
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
});
}