mirror of https://github.com/yewstack/yew
Size Comparison on Pull Requests (#2513)
* Fix optimisation flags. * Add size comparison. * Set opt-level to z. * Fix Workflow. * Fix Workflow. * Ignore failures. * Fix comment script. * Fix github script. * Separate Post Comments and Size Information Collection.
This commit is contained in:
parent
cb118377d6
commit
605f891a20
|
@ -53,7 +53,7 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
with:
|
||||
path: "./yew"
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
ref: "${{ github.head_ref }}"
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -89,6 +89,18 @@ jobs:
|
|||
${{ runner.os }}-benchmark-
|
||||
${{ runner.os }}
|
||||
|
||||
# Optimisation flags has no effect unless set at workspace level.
|
||||
- name: Write optimisation flags
|
||||
run: |
|
||||
cat >> Cargo.toml << EOF
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
EOF
|
||||
with:
|
||||
working-directory: yew
|
||||
|
||||
- name: save yew-struct setup
|
||||
shell: bash
|
||||
run: |
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
---
|
||||
name: Post Comment for Size Comparison
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Size Comparison"]
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
size-cmp:
|
||||
name: Post Comment on Pull Request
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- if: github.event.workflow_run.event == 'pull_request'
|
||||
name: Download Artifact
|
||||
uses: Legit-Labs/action-download-artifact@v2
|
||||
with:
|
||||
github_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
workflow: size-cmp.yml
|
||||
run_id: ${{ github.event.workflow_run.id }}
|
||||
name: size-cmp-info
|
||||
path: "size-cmp-info/"
|
||||
|
||||
- name: Make pull request comment
|
||||
run: |
|
||||
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")
|
||||
|
||||
shell: python3 {0}
|
||||
|
||||
- name: Post Comment
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const commentInfo = {
|
||||
...context.repo,
|
||||
issue_number: ${{ env.PR_NUMBER }},
|
||||
};
|
||||
|
||||
const comment = {
|
||||
...commentInfo,
|
||||
body: JSON.parse(process.env.YEW_EXAMPLE_SIZES),
|
||||
};
|
||||
|
||||
function isCommentByBot(comment) {
|
||||
return comment.user.type === "Bot" && comment.body.includes("### Size Comparison");
|
||||
}
|
||||
|
||||
let commentId = null;
|
||||
const comments = (await github.rest.issues.listComments(commentInfo)).data;
|
||||
for (let i = comments.length; i--; ) {
|
||||
const c = comments[i];
|
||||
if (isCommentByBot(c)) {
|
||||
commentId = c.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (commentId) {
|
||||
try {
|
||||
await github.rest.issues.updateComment({
|
||||
...context.repo,
|
||||
comment_id: commentId,
|
||||
body: comment.body,
|
||||
});
|
||||
} catch (e) {
|
||||
commentId = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!commentId) {
|
||||
await github.rest.issues.createComment(comment);
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
---
|
||||
name: Size Comparison
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
paths:
|
||||
- "packages/**"
|
||||
- "examples/**"
|
||||
- "Cargo.toml"
|
||||
|
||||
jobs:
|
||||
size-cmp:
|
||||
name: Compare Size between master and current Pull Request
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout master
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: 'yewstack/yew'
|
||||
ref: master
|
||||
path: yew-master
|
||||
|
||||
- name: Checkout pull request
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: current-pr
|
||||
|
||||
- name: Setup toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: wasm32-unknown-unknown
|
||||
override: true
|
||||
profile: minimal
|
||||
|
||||
- name: Restore Rust cache for master
|
||||
uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
working-directory: yew-master
|
||||
key: master
|
||||
|
||||
- name: Restore Rust cache for current pull request
|
||||
uses: Swatinem/rust-cache@v1
|
||||
with:
|
||||
working-directory: current-pr
|
||||
key: pr
|
||||
|
||||
- name: Setup Trunk
|
||||
uses: jetli/trunk-action@v0.1.0
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Write optimisation flags for master
|
||||
run: |
|
||||
cat >> Cargo.toml << EOF
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
opt-level = "z"
|
||||
EOF
|
||||
working-directory: yew-master
|
||||
|
||||
- name: Write optimisation flags for pull request
|
||||
run: |
|
||||
cat >> Cargo.toml << EOF
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
opt-level = "z"
|
||||
EOF
|
||||
working-directory: current-pr
|
||||
|
||||
- name: Build master examples
|
||||
run: find examples/*/index.html | xargs -I '{}' trunk build --release '{}' || exit 0
|
||||
working-directory: yew-master
|
||||
|
||||
- name: Build pull request examples
|
||||
run: find examples/*/index.html | xargs -I '{}' trunk build --release '{}' || exit 0
|
||||
working-directory: current-pr
|
||||
|
||||
- name: Make pull request comment
|
||||
run: |
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import glob
|
||||
import os
|
||||
import json
|
||||
|
||||
def find_example_sizes(parent_dir: str) -> Dict[str, int]:
|
||||
example_sizes: Dict[str, int] = {}
|
||||
|
||||
for example_dir in os.listdir(f"{parent_dir}/examples"):
|
||||
path = f"{parent_dir}/examples/{example_dir}"
|
||||
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
|
||||
matches = glob.glob(f"{parent_dir}/examples/{example_dir}/dist/index*.wasm")
|
||||
|
||||
if not matches:
|
||||
continue
|
||||
|
||||
path = matches[0]
|
||||
|
||||
example_sizes[example_dir] = os.path.getsize(path)
|
||||
|
||||
return example_sizes
|
||||
|
||||
master_sizes = find_example_sizes("yew-master")
|
||||
pr_sizes = find_example_sizes("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": ${{ github.event.number }},
|
||||
}
|
||||
|
||||
with open(".SIZE_CMP_INFO", "w+") as f:
|
||||
f.write(json.dumps(size_cmp_info))
|
||||
|
||||
shell: python3 {0}
|
||||
|
||||
- name: Update Artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: size-cmp-info
|
||||
path: ".SIZE_CMP_INFO"
|
||||
retention-days: 1
|
|
@ -14,10 +14,5 @@ wasm-bindgen = "=0.2.78"
|
|||
web-sys = { version = "0.3.55", features = ["Window"]}
|
||||
yew = "0.19.3"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = ['-O4']
|
||||
|
|
|
@ -14,10 +14,5 @@ wasm-bindgen = "=0.2.78"
|
|||
web-sys = { version = "0.3.55", features = ["Window"]}
|
||||
yew = "0.19.3"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = ['-O4']
|
||||
|
|
Loading…
Reference in New Issue