yew/ci/collect_sizes.py
Kaede Hoshikawa 6a568a5379
Fix Size Comparison (#2656)
* Update Scripts.

* Try to limit this to the main application.

* Use actual file.

* Sum size of all bundles.

* Update ci/make_example_size_cmt.py

Co-authored-by: WorldSEnder <WorldSEnder@users.noreply.github.com>

Co-authored-by: WorldSEnder <WorldSEnder@users.noreply.github.com>
2022-05-04 19:15:12 +09:00

53 lines
1.3 KiB
Python

from typing import Dict, List, Optional
from pathlib import Path
import glob
import os
import json
def find_example_sizes(parent_dir: Path) -> Dict[str, int]:
example_sizes: Dict[str, int] = {}
for example_dir in (parent_dir / "examples").iterdir():
if not example_dir.is_dir():
print(f"{example_dir} is not a directory.")
continue
total_size = 0
# For examples with multiple bundles, we add them together.
for bundle in (example_dir / "dist").glob(f"*.wasm"):
size = bundle.stat().st_size
print(f"{bundle} has a size of {size}.")
total_size += size
if total_size > 0:
example_sizes[example_dir.name] = total_size
return example_sizes
def main() -> None:
master_sizes = find_example_sizes(Path("yew-master"))
pr_sizes = find_example_sizes(Path("current-pr"))
example_names = sorted(set([*master_sizes.keys(), *pr_sizes.keys()]))
joined_sizes = [(i, [master_sizes.get(i), pr_sizes.get(i)]) for i in example_names]
size_cmp_info = {
"sizes": joined_sizes,
"issue_number": os.environ["ISSUE_NUMBER"],
}
with open(".SIZE_CMP_INFO", "w+") as f:
f.write(json.dumps(size_cmp_info, indent=4))
if __name__ == "__main__":
main()