CI/SizeComment: enhance PR commenting logic to update existing comments

This commit is contained in:
xtqqczze
2026-04-13 18:02:33 +01:00
committed by Sylvestre Ledru
parent e5a6b519ad
commit 4011e6dae6
+34 -12
View File
@@ -58,26 +58,48 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
const fs = require('fs');
if (!fs.existsSync('./NR') || !fs.existsSync('./result.txt')) {
core.info("No size comment payload to post.");
return;
}
var issue_number = Number(fs.readFileSync('./NR'));
const issue_number = Number(fs.readFileSync('./NR'));
if (!issue_number) {
core.info("No PR number; skipping.");
return;
}
var content = fs.readFileSync('./result.txt');
// Only comment when there is something meaningful to say.
// compare_size_results.py only writes the file when there is a
// significant change, so an empty/short body is treated as
// "nothing to report".
if (content.toString().trim().length > 0) {
const content = fs.readFileSync('./result.txt').toString();
const marker = '<!-- size-comment-bot -->';
const body = `${marker}\nBinary size comparison:\n\`\`\`\n${content}\n\`\`\``;
const { data: comments } = await github.rest.issues.listComments({
...context.repo,
issue_number
});
const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
...context.repo,
comment_id: existing.id,
body
});
} else {
// Only comment when there is something meaningful to say.
// compare_size_results.py only writes the file when there is a
// significant change, so an empty/short body is treated as
// "nothing to report".
if (content.trim().length == 0) {
return;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'Binary size comparison:\n```\n' + content + '```'
...context.repo,
issue_number,
body
});
}