From 387141817467291af1b5e13dd514fcb3ee542351 Mon Sep 17 00:00:00 2001 From: WorldSEnder Date: Thu, 22 Aug 2024 17:04:04 +0200 Subject: [PATCH] Modernize github workflows (#3711) * modernize github workflows this mainly fixes some inconsistencies in style, outdated or wrong comments and action version - replace Legit-Labs/action-download-artifact with actions/download-artifact - fix Swatinem/rust-cache arguments - fix benchmark transformations - expand feature soundness lints - wording and capitalization in comments * fix no_run on crate level doc * fix some more small issues --- .github/workflows/benchmark-core.yml | 23 +++------ .github/workflows/benchmark-ssr.yml | 19 +++---- .github/workflows/benchmark.yml | 50 ++++++++++-------- .github/workflows/build-api-docs.yml | 6 +-- .github/workflows/build-website.yml | 6 +-- .github/workflows/clippy.yml | 24 ++++----- .github/workflows/main-checks.yml | 10 +++- .github/workflows/post-benchmark-core.yml | 22 +++----- .github/workflows/post-benchmark-ssr.yml | 20 +++----- .github/workflows/post-benchmark.yml | 10 ++-- .github/workflows/post-size-cmp.yml | 24 ++++----- .github/workflows/publish-api-docs.yml | 27 ++++------ .github/workflows/publish-examples.yml | 2 + .github/workflows/publish-website.yml | 27 ++++------ .github/workflows/size-cmp.yml | 3 +- .github/workflows/test-website.yml | 8 +-- .gitignore | 1 + Cargo.toml | 1 - ci/build-examples.sh | 8 +-- ci/feature-soundness-release.sh | 30 +++++------ ci/feature-soundness.sh | 30 +++++------ ci/install-wasm-bindgen-cli.sh | 1 + packages/yew/src/lib.rs | 4 +- packages/yew/src/renderer.rs | 3 ++ tools/process-benchmark-results/src/main.rs | 56 +++++++++++++++++---- 25 files changed, 200 insertions(+), 215 deletions(-) diff --git a/.github/workflows/benchmark-core.yml b/.github/workflows/benchmark-core.yml index 5e7d0a943e4..94d6e6f6c54 100644 --- a/.github/workflows/benchmark-core.yml +++ b/.github/workflows/benchmark-core.yml @@ -1,4 +1,3 @@ ---- name: Benchmark - core on: @@ -32,29 +31,21 @@ jobs: with: toolchain: stable - - name: Restore Rust cache for master + - name: Restore Rust cache for yew packages uses: Swatinem/rust-cache@v2 with: - working-directory: yew-master - key: master - - - name: Restore Rust cache for current pull request - uses: Swatinem/rust-cache@v2 - with: - working-directory: current-pr - key: pr + shared-key: yew-packages + workspaces: | + yew-master + current-pr - name: Run pull request benchmark - run: cargo bench -q > ../output.log working-directory: current-pr/tools/benchmark-core + run: cargo bench -q > ../output.log - name: Run master benchmark - run: cargo bench -q > ../output.log - continue-on-error: true working-directory: yew-master/tools/benchmark-core - - - name: Make sure master's output log exists - run: touch yew-master/tools/output.log + run: cargo bench -q > ../output.log - name: Write Pull Request ID run: | diff --git a/.github/workflows/benchmark-ssr.yml b/.github/workflows/benchmark-ssr.yml index c470077adb6..536ccc71387 100644 --- a/.github/workflows/benchmark-ssr.yml +++ b/.github/workflows/benchmark-ssr.yml @@ -1,4 +1,3 @@ ---- name: Benchmark - SSR on: @@ -37,25 +36,21 @@ jobs: toolchain: stable targets: wasm32-unknown-unknown - - name: Restore Rust cache for master + - name: Restore Rust cache for yew packages uses: Swatinem/rust-cache@v2 with: - working-directory: yew-master - key: master - - - name: Restore Rust cache for current pull request - uses: Swatinem/rust-cache@v2 - with: - working-directory: current-pr - key: pr + shared-key: yew-packages + workspaces: | + yew-master + current-pr - name: Run pull request benchmark - run: cargo run --profile=bench -- --output-path ../output.json working-directory: current-pr/tools/benchmark-ssr + run: cargo run --profile=bench -- --output-path ../output.json - name: Run master benchmark - run: cargo run --profile=bench -- --output-path ../output.json working-directory: yew-master/tools/benchmark-ssr + run: cargo run --profile=bench -- --output-path ../output.json - name: Write Pull Request ID run: | diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3eccceb4a52..162d76d921b 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -11,11 +11,11 @@ on: - "website/**" types: [labeled, synchronize, opened, reopened] -permissions: - # deployments permission to deploy GitHub pages website - deployments: write - # contents permission to update benchmark contents in gh-pages branch - contents: write +# Cancel outstanding benchmarks on pull requests +# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true jobs: benchmark: @@ -37,31 +37,37 @@ jobs: toolchain: stable targets: wasm32-unknown-unknown - - uses: jetli/wasm-pack-action@v0.4.0 - with: - version: "latest" + - name: Setup wasm-pack + uses: jetli/wasm-pack-action@v0.4.0 - name: Setup Node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: ">=18" cache: "npm" cache-dependency-path: js-framework-benchmark/package-lock.json - - uses: Swatinem/rust-cache@v2 + - name: Restore Rust cache for yew packages + uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages + workspaces: | + yew + - name: Setup chrome + id: setup-chrome uses: browser-actions/setup-chrome@v1 with: install-chromedriver: true - - name: setup js-framework-benchmark + - name: Setup js-framework-benchmark working-directory: js-framework-benchmark run: | npm ci npm run install-server npm run install-webdriver-ts - - name: setup benchmark-struct benchmark + - name: Setup benchmark-struct benchmark run: | ls -lauh rm *.js @@ -69,7 +75,7 @@ jobs: echo "STRUCT_BUILD_DIR=$PWD" >> $GITHUB_ENV working-directory: js-framework-benchmark/frameworks/keyed/yew/bundled-dist/ - - name: build benchmark-struct app + - name: Build benchmark-struct app working-directory: yew/tools/benchmark-struct run: | wasm-pack build \ @@ -79,11 +85,11 @@ jobs: --out-name js-framework-benchmark-yew \ --out-dir $STRUCT_BUILD_DIR - - name: show built benchmark-struct benchmark files + - name: Show built benchmark-struct benchmark files run: | ls -lauh js-framework-benchmark/frameworks/keyed/yew/bundled-dist/ - - name: setup yew-hooks benchmark + - name: Setup yew-hooks benchmark run: | ls -lauh rm *.js @@ -91,7 +97,7 @@ jobs: echo "HOOKS_BUILD_DIR=$PWD" >> $GITHUB_ENV working-directory: js-framework-benchmark/frameworks/keyed/yew-hooks/bundled-dist/ - - name: build benchmark-hooks app + - name: Build benchmark-hooks app working-directory: yew/tools/benchmark-hooks run: | wasm-pack build \ @@ -101,25 +107,25 @@ jobs: --out-name js-framework-benchmark-yew-hooks \ --out-dir $HOOKS_BUILD_DIR - - name: show built benchmark-hooks benchmark files + - name: Show built benchmark-hooks benchmark files run: | ls -lauh js-framework-benchmark/frameworks/keyed/yew-hooks/bundled-dist/ - - name: run js-framework-benchmark server + - name: Run js-framework-benchmark server working-directory: js-framework-benchmark run: | npm start & sleep 5 - - name: js-framework-benchmark/webdriver-ts npm run bench + - name: Run js-framework-benchmark/webdriver-ts npm run bench working-directory: js-framework-benchmark/webdriver-ts - run: xvfb-run npm run bench -- --framework keyed/yew keyed/yew-hooks --runner playwright + run: xvfb-run npm run bench -- --framework keyed/yew keyed/yew-hooks --runner playwright --chromeBinary "${{ steps.setup-chrome.outputs.chrome-path }}" - - name: transform results to be fit for display benchmark-action/github-action-benchmark@v1 + - name: Transform results to be fit for display benchmark-action/github-action-benchmark@v1 run: | mkdir artifacts/ jq -s . js-framework-benchmark/webdriver-ts/results/*.json | cargo run --manifest-path yew/Cargo.toml --release -p process-benchmark-results > artifacts/results.json - echo "$EVENT_INFO" > artifacts/PR_INFO + echo "$EVENT_INFO" > artifacts/.PR_INFO env: EVENT_INFO: ${{ toJSON(github.event) }} diff --git a/.github/workflows/build-api-docs.yml b/.github/workflows/build-api-docs.yml index 62085f2e875..b3bdea488a7 100644 --- a/.github/workflows/build-api-docs.yml +++ b/.github/workflows/build-api-docs.yml @@ -16,8 +16,6 @@ on: jobs: build: runs-on: ubuntu-latest - env: - PR_INFO_FILE: ".PR_INFO" steps: - uses: actions/checkout@v4 @@ -55,12 +53,12 @@ jobs: - if: github.event_name == 'pull_request' name: Build pr info run: | - echo "${{ github.event.number }}" > $PR_INFO_FILE + echo "${{ github.event.number }}" > .PR_INFO - if: github.event_name == 'pull_request' name: Upload pr info uses: actions/upload-artifact@v4 with: name: pr-info - path: "${{ env.PR_INFO_FILE }}" + path: .PR_INFO retention-days: 1 diff --git a/.github/workflows/build-website.yml b/.github/workflows/build-website.yml index 6cc7c7a4454..2aead565a87 100644 --- a/.github/workflows/build-website.yml +++ b/.github/workflows/build-website.yml @@ -17,8 +17,6 @@ jobs: build: name: Build Website runs-on: ubuntu-latest - env: - PR_INFO_FILE: ".PR_INFO" steps: - uses: actions/checkout@v4 @@ -57,12 +55,12 @@ jobs: - if: github.event_name == 'pull_request' name: Build pr info run: | - echo "${{ github.event.number }}" > $PR_INFO_FILE + echo "${{ github.event.number }}" > .PR_INFO - if: github.event_name == 'pull_request' name: Upload pr info uses: actions/upload-artifact@v4 with: name: pr-info - path: "${{ env.PR_INFO_FILE }}" + path: .PR_INFO retention-days: 1 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index f8abed21053..6afd5bc7590 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -16,6 +16,9 @@ jobs: feature-soundness: name: Feature Soundness runs-on: ubuntu-latest + # if normal clippy doesn't succeed, do not try to lint feature soundness + needs: clippy + strategy: fail-fast: false matrix: @@ -32,27 +35,16 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 + with: + shared-key: clippy - name: Lint feature soundness if: matrix.profile == 'dev' - run: bash ../../ci/feature-soundness.sh - working-directory: packages/yew + run: bash ./ci/feature-soundness.sh - name: Lint feature soundness if: matrix.profile == 'release' - run: bash ../../ci/feature-soundness-release.sh - working-directory: packages/yew - - - name: Run release clippy - if: matrix.profile == 'release' - run: | - ls packages | xargs -I {} \ - cargo clippy \ - -p {} \ - --all-targets \ - --all-features \ - --workspace \ - -- -D warnings + run: bash ./ci/feature-soundness-release.sh clippy: name: Clippy Workspace @@ -73,6 +65,8 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 + with: + shared-key: clippy - name: Run clippy run: | diff --git a/.github/workflows/main-checks.yml b/.github/workflows/main-checks.yml index e825c3b143e..a1046bb97af 100644 --- a/.github/workflows/main-checks.yml +++ b/.github/workflows/main-checks.yml @@ -28,6 +28,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages # for wasm-bindgen-cli, always use stable rust - name: Setup toolchain @@ -74,6 +76,8 @@ jobs: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages # for wasm-bindgen-cli, always use stable rust - name: Setup toolchain @@ -122,8 +126,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Setup toolchain uses: dtolnay/rust-toolchain@master @@ -131,6 +133,8 @@ jobs: toolchain: ${{ matrix.toolchain }} - uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages - name: Run native tests env: @@ -159,6 +163,8 @@ jobs: toolchain: nightly - uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages - name: Run tests env: diff --git a/.github/workflows/post-benchmark-core.yml b/.github/workflows/post-benchmark-core.yml index 5a54eba0471..5f2b563ca3c 100644 --- a/.github/workflows/post-benchmark-core.yml +++ b/.github/workflows/post-benchmark-core.yml @@ -1,4 +1,3 @@ ---- name: Post Comment for Benchmark - core on: @@ -9,8 +8,8 @@ on: jobs: post-benchmark-core: - if: github.event.workflow_run.event == 'pull_request' - name: Post Comment on Pull Request + name: Post Benchmark Comment on Pull Request + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' runs-on: ubuntu-latest steps: @@ -18,13 +17,12 @@ jobs: uses: actions/checkout@v4 - name: Download Artifact - uses: Legit-Labs/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: benchmark-core.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: benchmark-core - path: "benchmark-core/" + path: benchmark-core/ - name: Make pull request comment run: | @@ -45,13 +43,7 @@ jobs: EOF - name: Read Pull Request ID - run: | - PR_NUMBER=$(cat "benchmark-core/.PR_NUMBER") - if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then - echo "pr number invalid" - exit 1 - fi - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + run: echo "PR_NUMBER=$(cat benchmark-core/.PR_NUMBER)" >> $GITHUB_ENV - name: Post Comment uses: actions/github-script@v6 diff --git a/.github/workflows/post-benchmark-ssr.yml b/.github/workflows/post-benchmark-ssr.yml index 2e874e10547..6cddabd8819 100644 --- a/.github/workflows/post-benchmark-ssr.yml +++ b/.github/workflows/post-benchmark-ssr.yml @@ -1,4 +1,3 @@ ---- name: Post Comment for Benchmark - SSR on: @@ -9,8 +8,8 @@ on: jobs: post-benchmark-ssr: - if: github.event.workflow_run.event == 'pull_request' name: Post Comment on Pull Request + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' runs-on: ubuntu-latest steps: @@ -18,25 +17,18 @@ jobs: uses: actions/checkout@v4 - name: Download Artifact - uses: Legit-Labs/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: benchmark-ssr.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: benchmark-ssr - path: "benchmark-ssr/" + path: benchmark-ssr/ - name: Make pull request comment run: python3 ci/make_benchmark_ssr_cmt.py - name: Read Pull Request ID - run: | - PR_NUMBER=$(cat "benchmark-ssr/.PR_NUMBER") - if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then - echo "pr number invalid" - exit 1 - fi - echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + run: echo "PR_NUMBER=$(cat benchmark-ssr/.PR_NUMBER)" >> $GITHUB_ENV - name: Post Comment uses: actions/github-script@v6 diff --git a/.github/workflows/post-benchmark.yml b/.github/workflows/post-benchmark.yml index fcbacf90c0a..d8e0aeda1e1 100644 --- a/.github/workflows/post-benchmark.yml +++ b/.github/workflows/post-benchmark.yml @@ -8,18 +8,18 @@ on: jobs: post-benchmark-results: - runs-on: ubuntu-latest if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest steps: # Checkout repo for the github-action-benchmark action - uses: actions/checkout@v4 - name: Download result artifacts - uses: Legit-Labs/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - workflow: benchmark.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: results path: ./artifacts @@ -27,7 +27,7 @@ jobs: uses: mathiasvr/command-output@v1 id: test-pr with: - run: cat artifacts/PR_INFO + run: cat artifacts/.PR_INFO # gh-pages branch is updated and pushed automatically with extracted benchmark data - name: Store benchmark result diff --git a/.github/workflows/post-size-cmp.yml b/.github/workflows/post-size-cmp.yml index 1e767b7a92e..ddd3f051018 100644 --- a/.github/workflows/post-size-cmp.yml +++ b/.github/workflows/post-size-cmp.yml @@ -1,4 +1,3 @@ ---- name: Post Comment for Size Comparison on: @@ -9,30 +8,27 @@ on: jobs: post-size-cmp: - name: Post Comment on Pull Request + name: Post Size Comment on Pull Request + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' runs-on: ubuntu-latest steps: - name: Download Repository uses: actions/checkout@v4 - - if: github.event.workflow_run.event == 'pull_request' - name: Download Artifact (master) - uses: Legit-Labs/action-download-artifact@v2 + - name: Download Artifact (master) + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: size-cmp.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: size-cmp-master-info path: "size-cmp-master-info/" - - if: github.event.workflow_run.event == 'pull_request' - name: Download Artifact (PR) - uses: Legit-Labs/action-download-artifact@v2 + - name: Download Artifact (PR) + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: size-cmp.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: size-cmp-pr-info path: "size-cmp-pr-info/" diff --git a/.github/workflows/publish-api-docs.yml b/.github/workflows/publish-api-docs.yml index 38c8822a348..a889948aee4 100644 --- a/.github/workflows/publish-api-docs.yml +++ b/.github/workflows/publish-api-docs.yml @@ -7,41 +7,34 @@ on: jobs: publish: + if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest - env: - PR_INFO_FILE: ".PR_INFO" - steps: - - if: github.event.workflow_run.conclusion != 'success' - name: Abort if build failed - run: | - echo "build failed" - exit 1 + steps: # need to checkout to get "firebase.json", ".firebaserc" - uses: actions/checkout@v4 - name: Download build artifact - uses: dawidd6/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: build-api-docs.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: api-docs path: api-docs/ - if: github.event.workflow_run.event == 'pull_request' name: Download pr info - uses: dawidd6/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: build-api-docs.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: pr-info + path: artifacts - if: github.event.workflow_run.event == 'pull_request' name: Apply pull request environment run: | - pr_number=$(cat "$PR_INFO_FILE") + pr_number=$(cat "artifacts/.PR_INFO") if ! [[ "$pr_number" =~ ^[0-9]+$ ]]; then echo "pr number invalid" exit 1 diff --git a/.github/workflows/publish-examples.yml b/.github/workflows/publish-examples.yml index 6a2219188fc..d800a9fa026 100644 --- a/.github/workflows/publish-examples.yml +++ b/.github/workflows/publish-examples.yml @@ -25,6 +25,8 @@ jobs: components: rust-src - uses: Swatinem/rust-cache@v2 + with: + shared-key: publish-examples - uses: jetli/trunk-action@v0.4.0 with: diff --git a/.github/workflows/publish-website.yml b/.github/workflows/publish-website.yml index 42d897528f1..a12f627f30d 100644 --- a/.github/workflows/publish-website.yml +++ b/.github/workflows/publish-website.yml @@ -7,41 +7,34 @@ on: jobs: publish: + if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest - env: - PR_INFO_FILE: ".PR_INFO" + steps: - - if: github.event.workflow_run.conclusion != 'success' - name: Abort if build failed - run: | - echo "build failed" - exit 1 # need to checkout to get "firebase.json", ".firebaserc" - uses: actions/checkout@v4 - name: Download build artifact - uses: Legit-Labs/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: build-website.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: website path: website/build - if: github.event.workflow_run.event == 'pull_request' name: Download pr info - uses: Legit-Labs/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - github_token: "${{ secrets.GITHUB_TOKEN }}" - workflow: build-website.yml - run_id: ${{ github.event.workflow_run.id }} + github-token: "${{ secrets.GITHUB_TOKEN }}" + run-id: ${{ github.event.workflow_run.id }} name: pr-info path: artifacts - if: github.event.workflow_run.event == 'pull_request' name: Apply pull request environment run: | - pr_number=$(cat "artifacts/$PR_INFO_FILE") + pr_number=$(cat "artifacts/.PR_INFO") if ! [[ "$pr_number" =~ ^[0-9]+$ ]]; then echo "pr number invalid" exit 1 @@ -49,10 +42,12 @@ jobs: echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV echo "PR_BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV echo "COMMIT_SHA=${{ github.event.workflow_run.head_sha }}" >> $GITHUB_ENV + - if: github.event.workflow_run.event == 'push' name: Apply push environment run: | echo "CHANNEL_ID=live" >> $GITHUB_ENV + - name: Deploy to Firebase uses: siku2/action-hosting-deploy@v1 with: diff --git a/.github/workflows/size-cmp.yml b/.github/workflows/size-cmp.yml index efaa041d6ca..cc507e3286e 100644 --- a/.github/workflows/size-cmp.yml +++ b/.github/workflows/size-cmp.yml @@ -1,4 +1,3 @@ ---- name: Size Comparison on: @@ -46,6 +45,8 @@ jobs: - name: Restore Rust cache for master uses: Swatinem/rust-cache@v2 + with: + shared-key: size-compare - name: Setup Trunk uses: jetli/trunk-action@v0.4.0 diff --git a/.github/workflows/test-website.yml b/.github/workflows/test-website.yml index 667fb0074ed..ebafcb6f8b0 100644 --- a/.github/workflows/test-website.yml +++ b/.github/workflows/test-website.yml @@ -1,4 +1,3 @@ ---- name: "Test Website" on: @@ -17,11 +16,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - # for wasm-bindgen-cli, always use stable rust - name: Setup toolchain uses: dtolnay/rust-toolchain@master @@ -39,6 +33,8 @@ jobs: targets: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 + with: + shared-key: yew-packages - uses: browser-actions/setup-geckodriver@latest with: diff --git a/.gitignore b/.gitignore index ff4c7afbdf4..bec5f8c71aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +dist/ # backup files generated by rustfmt **/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml index e68496c32e4..1c5626cc75d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,5 @@ opt-level = "z" [profile.bench] lto = true codegen-units = 1 -panic = "abort" opt-level = 3 diff --git a/ci/build-examples.sh b/ci/build-examples.sh index 69a0029d14b..843b1870ebc 100755 --- a/ci/build-examples.sh +++ b/ci/build-examples.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash # Must be run from root of the repo: # yew $ ./ci/build-examples.sh @@ -25,13 +26,6 @@ for path in examples/*; do cd "$path" dist_dir="$output/$example" export RUSTFLAGS="--cfg nightly_yew" - if [[ "$example" == "boids" || "$example" == "password_strength" ]]; then - # works around issue rust-lang/rust#96486 - # where the compiler forgets to link some symbols connected to const_eval - # only an issue on nightly and with build-std enabled which we do for code size - # this deoptimizes only the examples that otherwise fail to build - export RUSTFLAGS="-Zshare-generics=n -Clto=thin $RUSTFLAGS" - fi trunk build --release --dist "$dist_dir" --public-url "$PUBLIC_URL_PREFIX/$example" diff --git a/ci/feature-soundness-release.sh b/ci/feature-soundness-release.sh index 0fd501fba3c..19387aaeabb 100755 --- a/ci/feature-soundness-release.sh +++ b/ci/feature-soundness-release.sh @@ -2,19 +2,19 @@ set -xe # You can extract the feature list with the following command: -# cargo hack check --feature-powerset --exclude-features nightly +# cargo hack -p yew -p yew-agent -p yew-router --feature-powerset --print-command-list clippy --release -- -D warnings -# You need to run this script in packages/yew - -cargo clippy --release --no-default-features -- --deny=warnings -cargo clippy --release --no-default-features --features csr -- --deny=warnings -cargo clippy --release --no-default-features --features default -- --deny=warnings -cargo clippy --release --no-default-features --features csr,default -- --deny=warnings -cargo clippy --release --no-default-features --features hydration -- --deny=warnings -cargo clippy --release --no-default-features --features default,hydration -- --deny=warnings -cargo clippy --release --no-default-features --features ssr -- --deny=warnings -cargo clippy --release --no-default-features --features csr,ssr -- --deny=warnings -cargo clippy --release --no-default-features --features default,ssr -- --deny=warnings -cargo clippy --release --no-default-features --features csr,default,ssr -- --deny=warnings -cargo clippy --release --no-default-features --features hydration,ssr -- --deny=warnings -cargo clippy --release --no-default-features --features default,hydration,ssr -- --deny=warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features default,hydration,ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features csr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features default -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,default -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features hydration -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features default,hydration -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features default,ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,default,ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew/Cargo.toml --no-default-features --features hydration,ssr -- -D warnings +cargo clippy --release --manifest-path packages/yew-agent/Cargo.toml -- -D warnings +cargo clippy --release --manifest-path packages/yew-router/Cargo.toml -- -D warnings diff --git a/ci/feature-soundness.sh b/ci/feature-soundness.sh index b23b2592f73..e4067a531fe 100755 --- a/ci/feature-soundness.sh +++ b/ci/feature-soundness.sh @@ -2,19 +2,19 @@ set -xe # You can extract the feature list with the following command: -# cargo hack check --feature-powerset --exclude-features nightly +# cargo hack -p yew -p yew-agent -p yew-router --feature-powerset --print-command-list clippy -- -D warnings -# You need to run this script in packages/yew - -cargo clippy --no-default-features -- --deny=warnings -cargo clippy --no-default-features --features csr -- --deny=warnings -cargo clippy --no-default-features --features default -- --deny=warnings -cargo clippy --no-default-features --features csr,default -- --deny=warnings -cargo clippy --no-default-features --features hydration -- --deny=warnings -cargo clippy --no-default-features --features default,hydration -- --deny=warnings -cargo clippy --no-default-features --features ssr -- --deny=warnings -cargo clippy --no-default-features --features csr,ssr -- --deny=warnings -cargo clippy --no-default-features --features default,ssr -- --deny=warnings -cargo clippy --no-default-features --features csr,default,ssr -- --deny=warnings -cargo clippy --no-default-features --features hydration,ssr -- --deny=warnings -cargo clippy --no-default-features --features default,hydration,ssr -- --deny=warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features default,hydration,ssr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features csr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features default -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,default -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features hydration -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features default,hydration -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features ssr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,ssr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features default,ssr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features csr,default,ssr -- -D warnings +cargo clippy --manifest-path packages/yew/Cargo.toml --no-default-features --features hydration,ssr -- -D warnings +cargo clippy --manifest-path packages/yew-agent/Cargo.toml -- -D warnings +cargo clippy --manifest-path packages/yew-router/Cargo.toml -- -D warnings diff --git a/ci/install-wasm-bindgen-cli.sh b/ci/install-wasm-bindgen-cli.sh index e592a9c83b2..1962c94b3fd 100755 --- a/ci/install-wasm-bindgen-cli.sh +++ b/ci/install-wasm-bindgen-cli.sh @@ -1,3 +1,4 @@ +#!/usr/bin/env bash if [ ! -f "Cargo.lock" ]; then cargo fetch fi diff --git a/packages/yew/src/lib.rs b/packages/yew/src/lib.rs index cd85d32af3e..75442817802 100644 --- a/packages/yew/src/lib.rs +++ b/packages/yew/src/lib.rs @@ -30,7 +30,7 @@ //! //! ## Example //! -//! ```rust +//! ```rust,no_run //! use yew::prelude::*; //! //! enum Msg { @@ -68,11 +68,9 @@ //! } //! } //! -//! # fn dont_execute() { //! fn main() { //! yew::Renderer::::new().render(); //! } -//! # } //! ``` #![deny( diff --git a/packages/yew/src/renderer.rs b/packages/yew/src/renderer.rs index 7c7e20e63c6..591d5da07e7 100644 --- a/packages/yew/src/renderer.rs +++ b/packages/yew/src/renderer.rs @@ -1,4 +1,7 @@ use std::cell::Cell; +#[rustversion::since(1.81)] +use std::panic::PanicHookInfo as PanicInfo; +#[rustversion::before(1.81)] use std::panic::PanicInfo; use std::rc::Rc; diff --git a/tools/process-benchmark-results/src/main.rs b/tools/process-benchmark-results/src/main.rs index 66eb157bad3..8a7f30c200f 100644 --- a/tools/process-benchmark-results/src/main.rs +++ b/tools/process-benchmark-results/src/main.rs @@ -1,31 +1,65 @@ +use std::collections::HashMap; use std::io; use std::io::{Read, Write}; use anyhow::Result; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use serde_json::Value; #[derive(Serialize)] struct GhActionBenchmark { name: String, unit: String, - value: String, + value: Value, +} + +// from https://github.com/krausest/js-framework-benchmark/blob/master/webdriver-ts/src/writeResults.ts#L67 function createResultFile +#[derive(Deserialize)] +struct ResultData { + median: Value, + // some keys missing +} + +#[derive(Deserialize)] +struct JsKrauseBenchmarkResult<'r> { + framework: &'r str, + benchmark: &'r str, + r#type: &'r str, + values: HashMap<&'r str, ResultData>, +} + +fn transform_results(mut result: JsKrauseBenchmarkResult<'_>) -> GhActionBenchmark { + let key = if result.r#type == "cpu" { + "total" + } else { + "DEFAULT" + }; + let values = result.values.remove(key).unwrap_or_else(|| { + panic!( + "Expect benchmark data to be present for type {}. Found keys: {:?}, expected {key:?}", + result.r#type, + result.values.keys().cloned().collect::>(), + ) + }); + assert!( + values.median.is_number(), + "expected a numerical benchmark value" + ); + GhActionBenchmark { + name: format!("{} {}", result.framework, result.benchmark).replace('"', ""), + unit: String::default(), + value: values.median, + } } fn main() -> Result<()> { let mut buffer = "".to_string(); io::stdin().read_to_string(&mut buffer)?; - let input_json: Vec = serde_json::from_str(buffer.as_str())?; + let input_json: Vec<_> = serde_json::from_str(buffer.as_str())?; - let transformed_benchmarks: Vec = input_json - .into_iter() - .map(|v| GhActionBenchmark { - name: format!("{} {}", v["framework"], v["benchmark"]).replace('"', ""), - unit: String::default(), - value: v["median"].to_string(), - }) - .collect(); + let transformed_benchmarks: Vec = + input_json.into_iter().map(transform_results).collect(); let output = serde_json::to_string(&transformed_benchmarks)?;