| name: Examples | |
| # Checks every example: the Rust crates among them (members of the | |
| # workspace under `examples/`: their lints and tests, such as the Rust | |
| # gallery's black-box tests, which run every demo through the engine, | |
| # headless) and every app entry (a top-level `.tsx` of an example that calls | |
| # `mount`, and the `nsh.json` of a Rust app, one declaring a `"root"`), | |
| # built with `nsh build`. All are found, so a new example is checked | |
| # without a change here. The other workflows only run for | |
| # `crates/**`, so a change to the examples alone was never built. | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "examples/**" | |
| - ".github/workflows/examples.yml" | |
| pull_request: | |
| paths: | |
| - "examples/**" | |
| - ".github/workflows/examples.yml" | |
| merge_group: | |
| types: [checks_requested] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: examples-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| # CI builds each crate once: no incremental state and no debug info | |
| # (faster builds, smaller caches; panics still name their file and line). | |
| CARGO_INCREMENTAL: "0" | |
| CARGO_PROFILE_DEV_DEBUG: "0" | |
| # The toolchain file's iOS and Android targets are only the release's. | |
| RUSTUP_TOOLCHAIN: stable | |
| jobs: | |
| check: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # QuickJS is C (bindgen needs libclang). The Rust gallery also | |
| # links GTK through its native desktop entry's dependencies. | |
| - name: Install clang and GTK 4 | |
| run: sudo apt-get update && sudo apt-get install -y clang libclang-dev libgtk-4-dev jq | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: clippy | |
| # Dependencies only: main's runs save it, pull requests restore it. | |
| - name: Cache Cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| save-if: ${{ github.ref == 'refs/heads/main' }} | |
| - name: Find the Rust examples | |
| id: crates | |
| run: > | |
| echo "packages=$(cargo metadata --no-deps --format-version 1 | |
| | jq -r '[.packages[] | select(.manifest_path | contains("/examples/")) | "-p " + .name] | join(" ")')" | |
| >> "$GITHUB_OUTPUT" | |
| - name: Clippy | |
| if: steps.crates.outputs.packages != '' | |
| run: cargo clippy --all-targets ${{ steps.crates.outputs.packages }} -- -D warnings | |
| - name: Test | |
| if: steps.crates.outputs.packages != '' | |
| run: cargo test ${{ steps.crates.outputs.packages }} | |
| # An app with a Rust crate (`nsh.json` "rust") builds its own command | |
| # line with the crate first; a Rust app has no bundle, its build | |
| # gathers what it ships besides its runners. | |
| - name: Build the apps | |
| run: | | |
| cargo build -p nsh-cli | |
| for entry in $(grep -l "mount(" examples/*/*.tsx) $(grep -l '"root"' examples/*/nsh.json); do | |
| ./target/debug/nsh build "$entry" -o "$RUNNER_TEMP/bundles/${entry//\//_}" | |
| done |