Skip to content

Commit 54e4ec8

Browse files
committed
Move size reporting job into separate composite workflow.
1 parent 6a68ad8 commit 54e4ec8

File tree

2 files changed

+62
-40
lines changed

2 files changed

+62
-40
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Github composite action to report on code size changes
2+
name: Report binary size changes on PR
3+
description: |
4+
Report on code size changes resulting from a PR as a comment on the PR
5+
(accessed via context).
6+
inputs:
7+
reference:
8+
description: The size in bytes of the reference binary (base of PR).
9+
required: true
10+
updated:
11+
description: The size in bytes of the updated binary (head of PR).
12+
required: true
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Post a PR comment if the size has changed
17+
uses: actions/github-script@v6
18+
env:
19+
SIZE_REFERENCE: ${{ inputs.reference }}
20+
SIZE_UPDATED: ${{ inputs.updated }}
21+
with:
22+
script: |
23+
const reference = process.env.SIZE_REFERENCE;
24+
const updated = process.env.SIZE_UPDATED;
25+
26+
if (!(reference > 0)) {
27+
core.setFailed(`Reference size invalid: ${reference}`);
28+
return;
29+
}
30+
31+
if (!(updated > 0)) {
32+
core.setFailed(`Updated size invalid: ${updated}`);
33+
return;
34+
}
35+
36+
const diff = updated - reference;
37+
const plus = diff > 0 ? "+" : "";
38+
const diff_str = `${plus}${diff}B`;
39+
40+
if (diff !== 0) {
41+
const percent = (((updated / reference) - 1) * 100).toFixed(2);
42+
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines,
43+
// which is interpreted as a code block by Markdown.
44+
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace.
45+
46+
Original binary size: **${reference}B**
47+
Updated binary size: **${updated}B**
48+
Difference: **${diff_str}** (${percent}%)`;
49+
50+
github.rest.issues.createComment({
51+
issue_number: context.issue.number,
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
body
55+
})
56+
}

.github/workflows/check-binary-size.yml

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -94,44 +94,10 @@ jobs:
9494
permissions:
9595
pull-requests: write
9696
steps:
97-
- name: Post a PR comment if the size has changed
98-
uses: actions/github-script@v6
99-
env:
100-
SIZE_REFERENCE: ${{ needs.measure.outputs.binary-size-reference }}
101-
SIZE_UPDATED: ${{ needs.measure.outputs.binary-size-updated }}
97+
# Clone backtrace to access Github composite actions to report size.
98+
- uses: actions/checkout@v3
99+
# Run the size reporting action.
100+
- uses: ./.github/actions/report-code-size-changes
102101
with:
103-
script: |
104-
const reference = process.env.SIZE_REFERENCE;
105-
const updated = process.env.SIZE_UPDATED;
106-
107-
if (!(reference > 0)) {
108-
core.setFailed(`Reference size invalid: ${reference}`);
109-
return;
110-
}
111-
112-
if (!(updated > 0)) {
113-
core.setFailed(`Updated size invalid: ${updated}`);
114-
return;
115-
}
116-
117-
const diff = updated - reference;
118-
const plus = diff > 0 ? "+" : "";
119-
const diff_str = `${plus}${diff}B`;
120-
121-
if (diff !== 0) {
122-
const percent = (((updated / reference) - 1) * 100).toFixed(2);
123-
// The body is created here and wrapped so "weirdly" to avoid whitespace at the start of the lines,
124-
// which is interpreted as a code block by Markdown.
125-
const body = `Below is the size of a hello-world Rust program linked with libstd with backtrace.
126-
127-
Original binary size: **${reference}B**
128-
Updated binary size: **${updated}B**
129-
Difference: **${diff_str}** (${percent}%)`;
130-
131-
github.rest.issues.createComment({
132-
issue_number: context.issue.number,
133-
owner: context.repo.owner,
134-
repo: context.repo.repo,
135-
body
136-
})
137-
}
102+
reference: ${{ needs.measure.outputs.binary-size-reference }}
103+
updated: ${{ needs.measure.outputs.binary-size-updated }}

0 commit comments

Comments
 (0)