Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into scoped-events
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldSEnder committed Mar 22, 2022
2 parents df3b8e0 + 62d78d0 commit f59633f
Show file tree
Hide file tree
Showing 127 changed files with 2,302 additions and 1,970 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,6 +89,17 @@ 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
working-directory: yew

- name: save yew-struct setup
shell: bash
run: |
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ jobs:
command: clippy
args: --all-targets -- -D warnings

- name: Lint feature soundness
run: |
cargo clippy -- --deny=warnings
cargo clippy --features=ssr -- --deny=warnings
cargo clippy --features=csr -- --deny=warnings
cargo clippy --all-features --all-targets -- --deny=warnings
working-directory: packages/yew


clippy-release:
name: Clippy on release profile
Expand All @@ -49,6 +57,14 @@ jobs:
command: clippy
args: --all-targets --release -- -D warnings

- name: Lint feature soundness
run: |
cargo clippy --release -- --deny=warnings
cargo clippy --release --features=ssr -- --deny=warnings
cargo clippy --release --features=csr -- --deny=warnings
cargo clippy --release --all-features --all-targets -- --deny=warnings
working-directory: packages/yew


doc_tests:
name: Documentation Tests
Expand Down Expand Up @@ -180,4 +196,3 @@ jobs:
with:
command: test
args: -p yew-macro test_html_lints --features lints

116 changes: 116 additions & 0 deletions .github/workflows/post-size-cmp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
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"]
issue_number = content["issue_number"]
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={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);
}
135 changes: 135 additions & 0 deletions .github/workflows/size-cmp.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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: Collect size information
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: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: size-cmp-info
path: ".SIZE_CMP_INFO"
retention-days: 1
2 changes: 1 addition & 1 deletion examples/agents/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ license = "MIT OR Apache-2.0"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
yew-agent = { path = "../../packages/yew-agent" }
gloo-timers = "0.2"
2 changes: 1 addition & 1 deletion examples/agents/src/bin/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::start_app::<agents::App>();
yew::Renderer::<agents::App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/boids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ anyhow = "1.0"
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo = "0.6"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ impl App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
Loading

0 comments on commit f59633f

Please sign in to comment.