Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions .github/workflows/SizeComment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Loading