@@ -58,26 +58,48 @@ jobs:
5858 with :
5959 github-token : ${{ secrets.GITHUB_TOKEN }}
6060 script : |
61- var fs = require('fs');
61+ const fs = require('fs');
6262 if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) {
6363 core.info("No size comment payload to post.");
6464 return;
6565 }
66- var issue_number = Number(fs.readFileSync('./NR'));
66+ const issue_number = Number(fs.readFileSync('./NR'));
6767 if (!issue_number) {
6868 core.info("No PR number; skipping.");
6969 return;
7070 }
71- var content = fs.readFileSync('./result.txt');
72- // Only comment when there is something meaningful to say.
73- // compare_size_results.py only writes the file when there is a
74- // significant change, so an empty/short body is treated as
75- // "nothing to report".
76- if (content.toString().trim().length > 0) {
71+ const content = fs.readFileSync('./result.txt').toString();
72+
73+ const marker = '<!-- size-comment-bot -->';
74+ const body = `${marker}\nBinary size comparison:\n\`\`\`\n${content}\n\`\`\``;
75+
76+ const { data: comments } = await github.rest.issues.listComments({
77+ ...context.repo,
78+ issue_number
79+ });
80+
81+ const existing = comments.find(c =>
82+ c.user.login === 'github-actions[bot]' &&
83+ c.body.includes(marker)
84+ );
85+
86+ if (existing) {
87+ await github.rest.issues.updateComment({
88+ ...context.repo,
89+ comment_id: existing.id,
90+ body
91+ });
92+ } else {
93+ // Only comment when there is something meaningful to say.
94+ // compare_size_results.py only writes the file when there is a
95+ // significant change, so an empty/short body is treated as
96+ // "nothing to report".
97+ if (content.trim().length == 0) {
98+ return;
99+ }
77100 await github.rest.issues.createComment({
78- owner: context.repo.owner,
79- repo: context.repo.repo,
80- issue_number: issue_number,
81- body: 'Binary size comparison:\n```\n' + content + '```'
101+ ...context.repo,
102+ issue_number,
103+ body
82104 });
83105 }
0 commit comments