Skip to content

Commit

Permalink
Update examples and their builds in CI (#2652)
Browse files Browse the repository at this point in the history
- Remove agents example
- Agents example is replaced by web_worker_fib as they both serve the same purpose now that trunk 0.15 has been released
- Clean up CI setup and ensure that examples are deployed in publish-examples.yml as they're built in size-cmp.yml
  • Loading branch information
hamza1311 committed May 3, 2022
1 parent 8d9ecf2 commit 3159424
Show file tree
Hide file tree
Showing 25 changed files with 164 additions and 386 deletions.
1 change: 1 addition & 0 deletions .cargo/config → .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ runner = 'wasm-bindgen-test-runner'

[unstable]
doctest-xcompile = true
# [unstable] must be the last section -- ci/write-optimisation-flags.sh relies on it
47 changes: 7 additions & 40 deletions .github/workflows/publish-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,29 @@ jobs:
env:
# leave empty for /
PUBLIC_URL_PREFIX: ""
RUSTUP_TOOLCHAIN: nightly

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
target: wasm32-unknown-unknown
components: rust-src
override: true
profile: minimal

- name: Write optimisation flags
run: ./ci/write-optimisation-flags.sh

- uses: Swatinem/rust-cache@v1

- uses: jetli/trunk-action@v0.1.0
with:
# Optional version of trunk to install(eg. 'v0.8.1', 'latest')
version: 'latest'



- name: Build examples
run: |
output="$(pwd)/dist"
mkdir "$output"
for path in examples/*; do
if [[ ! -d $path ]]; then
continue
fi
example=$(basename "$path")
# multi_thread doesn't work yet. See <https://github.com/thedodd/trunk/issues/40>.
if [[ "$example" == "agents" ]]; then
continue
fi
# web_worker_fib does not compile with trunk. See <https://github.com/thedodd/trunk/issues/46>.
if [[ "$example" == "web_worker_fib" ]]; then
continue
fi
# ssr does not need trunk
if [[ "$example" == "simple_ssr" ]]; then
continue
fi
echo "building: $example"
(
cd "$path"
dist_dir="$output/$example"
trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX/$example"
)
done
run: ./ci/build-examples.sh

- name: Deploy to Firebase
uses: siku2/action-hosting-deploy@v0
Expand Down
28 changes: 2 additions & 26 deletions .github/workflows/size-cmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,11 @@ jobs:
version: 'latest'

- name: Write optimisation flags for master
run: |
cat >> .cargo/config << EOF
[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
EOF
cat >> Cargo.toml << EOF
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
opt-level = "z"
EOF
run: ./ci/write-optimisation-flags.sh
working-directory: yew-master

- name: Write optimisation flags for pull request
run: |
cat >> .cargo/config << EOF
[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
EOF
cat >> Cargo.toml << EOF
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
opt-level = "z"
EOF
run: ./ci/write-optimisation-flags.sh
working-directory: current-pr

- name: Build master examples
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ members = [
"packages/yew-router-macro",

# Examples
"examples/agents",
"examples/boids",
"examples/contexts",
"examples/counter",
Expand Down
28 changes: 28 additions & 0 deletions ci/build-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Must be run from root of the repo:
# yew $ ./ci/build-examples.sh

output="$(pwd)/dist"
mkdir "$output"

for path in examples/*; do
if [[ ! -d $path ]]; then
continue
fi

example=$(basename "$path")

# ssr does not need trunk
if [[ "$example" == "simple_ssr" || "$example" == "ssr_router" ]]; then
continue
fi

echo "building: $example"
(
# we are sure that $path exists
# shellcheck disable=SC2164
cd "$path"
dist_dir="$output/$example"

echo trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX$example"
)
done
15 changes: 15 additions & 0 deletions ci/write-optimisation-flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Must be run from root of the repo:
# yew $ ./ci/write-optimisation-flags.sh

# this goes in [unstable] section
cat >> .cargo/config << EOF
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort"]
EOF
cat >> Cargo.toml << EOF
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
opt-level = "z"
EOF
9 changes: 4 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ As an example, check out the TodoMVC example here: <https://examples.yew.rs/todo

| Example | CT | Description |
| -------------------------------------------------- | -- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [agents](agents) | S | Cross-component communication using [Agents](https://yew.rs/docs/concepts/agents) |
| [boids](boids) | S | Yew port of [Boids](https://en.wikipedia.org/wiki/Boids) |
| [contexts](contexts) | F | A technical demonstration of Context API. |
| [counter](counter) | S | Simple counter which can be incremented and decremented |
Expand All @@ -40,7 +39,7 @@ As an example, check out the TodoMVC example here: <https://examples.yew.rs/todo
| [futures](futures) | S | Demonstrates how you can use futures and async code with Yew. Features a Markdown renderer. |
| [game_of_life](game_of_life) | S | Implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) |
| [inner_html](inner_html) | S | Embeds an external document as raw HTML by manually managing the element |
| [js_callback](js_callback) | S | Interacts with JavaScript code |
| [js_callback](js_callback) | F | Interacts with JavaScript code |
| [keyed_list](keyed_list) | S | Demonstrates how to use keys to improve the performance of lists |
| [mount_point](mount_point) | S | Shows how to mount the root component to a custom element |
| [nested_list](nested_list) | S | Renders a styled list which tracks hover events |
Expand All @@ -49,12 +48,12 @@ As an example, check out the TodoMVC example here: <https://examples.yew.rs/todo
| [portals](portals) | S | Renders elements into out-of-tree nodes with the help of portals |
| [router](router) | S | The best yew blog built with `yew-router` |
| [simple_ssr](simple_ssr) | F | Demonstrates server-side rendering |
| [suspense](suspense) | F | This is an example that demonstrates `<Suspense />` support |
| [function_memory_game](function_memory_game) | F | Implementation of [Memory Game](https://github.com/bradlygreen/Memory-Game) |
| [suspense](suspense) | F | This is an example that demonstrates `<Suspense />` support |
| [function_memory_game](function_memory_game) | F | Implementation of [Memory Game](https://github.com/bradlygreen/Memory-Game) |
| [timer](timer) | S | Demonstrates the use of the interval and timeout services |
| [todomvc](todomvc) | S | Implementation of [TodoMVC](http://todomvc.com/) |
| [two_apps](two_apps) | S | Runs two separate Yew apps which can communicate with each other |
| [web_worker_fib](web_worker_fib) | S | Calculate fibonacci value of a number in a web worker thread |
| [web_worker_fib](web_worker_fib) | S | Calculate fibonacci value of a number in a web worker thread using `gloo-worker` |
| [webgl](webgl) | S | Controls a [WebGL canvas](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial/Getting_started_with_WebGL) from Yew |

## Next steps
Expand Down
14 changes: 0 additions & 14 deletions examples/agents/Cargo.toml

This file was deleted.

18 changes: 0 additions & 18 deletions examples/agents/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions examples/agents/index.html

This file was deleted.

4 changes: 0 additions & 4 deletions examples/agents/src/bin/app.rs

This file was deleted.

7 changes: 0 additions & 7 deletions examples/agents/src/bin/worker.rs

This file was deleted.

51 changes: 0 additions & 51 deletions examples/agents/src/lib.rs

This file was deleted.

64 changes: 0 additions & 64 deletions examples/agents/src/native_worker.rs

This file was deleted.

3 changes: 0 additions & 3 deletions examples/web_worker_fib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.0"
edition = "2021"
authors = ["Shrey Somaiya", "Zac Kologlu"]

[lib]
crate-type = ["cdylib"]

[dependencies]
yew = { path = "../../packages/yew", features = ["csr"] }
yew-agent = { path = "../../packages/yew-agent" }
Expand Down

1 comment on commit 3159424

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: 3159424 Previous: 8d9ecf2 Ratio
yew-struct-keyed 01_run1k 172.02 160.2375 1.07
yew-struct-keyed 02_replace1k 181.7675 176.125 1.03
yew-struct-keyed 03_update10th1k_x16 396.412 349.404 1.13
yew-struct-keyed 04_select1k 60.592 63.227999999999994 0.96
yew-struct-keyed 05_swap1k 87.043 72.81700000000001 1.20
yew-struct-keyed 06_remove-one-1k 26.724 25.8765 1.03
yew-struct-keyed 07_create10k 2914.058 2784.907 1.05
yew-struct-keyed 08_create1k-after1k_x2 408.0675 389.4 1.05
yew-struct-keyed 09_clear1k_x8 187.7715 176.356 1.06
yew-struct-keyed 21_ready-memory 1.457233428955078 1.457233428955078 1
yew-struct-keyed 22_run-memory 1.6929817199707031 1.6942291259765625 1.00
yew-struct-keyed 23_update5-memory 1.6955795288085938 1.6755828857421875 1.01
yew-struct-keyed 24_run5-memory 1.9444847106933592 1.9438438415527344 1.00
yew-struct-keyed 25_run-clear-memory 1.32781982421875 1.3279914855957031 1.00
yew-struct-keyed 31_startup-ci 1881.465 1731.1239999999998 1.09
yew-struct-keyed 32_startup-bt 28.807999999999996 28.304 1.02
yew-struct-keyed 33_startup-mainthreadcost 228.412 211.08 1.08
yew-struct-keyed 34_startup-totalbytes 328.7421875 328.7373046875 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.