Skip to content

Commit

Permalink
Format code size differences with grouping and unit display.
Browse files Browse the repository at this point in the history
  • Loading branch information
detly committed Aug 27, 2023
1 parent 54e4ec8 commit 17fbabb
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions .github/actions/report-code-size-changes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,34 @@ runs:
return;
}
const formatter = Intl.NumberFormat("en", {useGrouping: "always"});
const updated_str = formatter.format(updated);
const reference_str = formatter.format(reference);
const diff = updated - reference;
const plus = diff > 0 ? "+" : "";
const diff_str = `${plus}${diff}B`;
const diff_pct = (updated / reference) - 1;
const diff_str = Intl.NumberFormat("en", {
useGrouping: "always",
sign: "exceptZero"
}).format(diff);
const diff_pct_str = Intl.NumberFormat("en", {
style: "percent",
useGrouping: "always",
sign: "exceptZero",
maximumFractionDigits: 2
}).format(diff_pct);
if (diff !== 0) {
const percent = (((updated / reference) - 1) * 100).toFixed(2);
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines,
// which is interpreted as a code block by Markdown.
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace.
Original binary size: **${reference}B**
Updated binary size: **${updated}B**
Difference: **${diff_str}** (${percent}%)`;
Original binary size: **${reference_str} B**
Updated binary size: **${updated_str} B**
Difference: **${diff_str} B** (${diff_pct_str})`;
github.rest.issues.createComment({
issue_number: context.issue.number,
Expand Down

0 comments on commit 17fbabb

Please sign in to comment.