-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Size Comparison on Pull Requests #2513
Conversation
Hmm, seems like the build size comment is not going to take effect until this pull request is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not merge post-size-cmp.yml
and size-cmp.yml
? It's not like those 2 can run in parallel. It would help keep everything in once place and would also allow us to avoid the upload/download info step.
When a workflow is triggered on a pull request, it has no access to post comments on the base repository. You can use This means that the code needs to be compiled within the fork and the comment needs to be posted from base repository so we need 2 workflows. See: https://github.com/yewstack/yew/runs/5520333803?check_suite_focus=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that GITHUB_SECRET didn't have permissions to post a comment on the pull request.
Why didn't it approve auto approve for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me. If we want to refine this in the future, maybe have a discussion how we want to organize supplementary code, such as the ones in the yaml files.
from typing import Dict, List, Optional | ||
|
||
import os | ||
import json | ||
|
||
with open("size-cmp-info/.SIZE_CMP_INFO") as f: | ||
content = json.loads(f.read()) | ||
|
||
joined_sizes = content["sizes"] | ||
|
||
lines: List[str] = [] | ||
|
||
lines.append("### Size Comparison") | ||
lines.append("") | ||
lines.append("| examples | master (KB) | pull request (KB) | diff |") | ||
lines.append("| --- | --- | --- | --- | ") | ||
|
||
for (i, sizes) in joined_sizes: | ||
(master_size, pr_size) = sizes | ||
diff: Optional[int] = None | ||
|
||
if master_size is not None and pr_size is not None: | ||
diff = pr_size - master_size | ||
|
||
master_size_str = "N/A" if master_size is None else ( | ||
f"{master_size / 1024:.3f}" if master_size != 0 else "0" | ||
) | ||
pr_size_str = "N/A" if pr_size is None else ( | ||
f"{pr_size / 1024:.3f}" if pr_size != 0 else "0" | ||
) | ||
diff_str = "N/A" if diff is None else ( | ||
f"{diff / 1024:.3f}" if diff < 0 else ( | ||
f"+{diff / 1024:.3f}" if diff > 0 else "0" | ||
) | ||
) | ||
lines.append(f"| {i} | {master_size_str} | {pr_size_str} | {diff_str} |") | ||
|
||
output = "\n".join(lines) | ||
|
||
with open(os.environ["GITHUB_ENV"], "a+") as f: | ||
f.write(f"YEW_EXAMPLE_SIZES={json.dumps(output)}\n") | ||
f.write(f"PR_NUMBER={content["issue_number"]}\n") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have these parts in proper files than inline in yaml files, but it's fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could go in the ci directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@futursolo, do you want to make this change? If not, please go ahead and merge this
Oh wow that is cool!!! |
Description
Fixes #2460
This pull request adds a comment on pull requests that compares the size of examples of master and pull requests.
Checklist
cargo make pr-flow
Preview
For every pull request, a comment like the following will be made on the pull request automatically.
Size Comparison