| name: Website | |
| # Builds the documentation site with its live demos (the WebAssembly runtime, | |
| # `cargo xtask web`) and publishes it to GitHub Pages at nsh.dev | |
| # (`website/public/CNAME`). | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "website/**" | |
| - "crates/**" | |
| - "examples/gallery/**" | |
| - "Cargo.toml" | |
| - "Cargo.lock" | |
| - ".cargo/**" | |
| - "rust-toolchain.toml" | |
| - ".github/workflows/website.yml" | |
| pull_request: | |
| paths: | |
| - "website/**" | |
| - "crates/nsh-platform-web/**" | |
| - "examples/gallery/**" | |
| - ".github/workflows/website.yml" | |
| merge_group: | |
| types: [checks_requested] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Pages takes one deployment at a time; queue rather than cancel, so the | |
| # latest push always ends up deployed. | |
| concurrency: | |
| group: pages-${{ github.ref }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }} | |
| 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: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # QuickJS is C: clang compiles it for wasm32 (llvm-ar archives it), and | |
| # bindgen needs libclang for the host build of the nsh CLI. | |
| - name: Install clang and LLVM | |
| run: sudo apt-get update && sudo apt-get install -y clang llvm libclang-dev | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: 1.4.2 | |
| # 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: Test browser scroll indicator behavior | |
| run: node --test crates/nsh-platform-web/web/scroll.test.mjs | |
| - name: Install website dependencies | |
| working-directory: website | |
| run: bun install | |
| # `build` runs `cargo xtask web` first: nsh.wasm, the player and every | |
| # demo in website/demos, into website/public/play, and the gallery | |
| # published with `nsh package --target web` into play/gallery. | |
| - name: Build website | |
| working-directory: website | |
| env: | |
| NSH_REQUIRE_PLAY: "1" | |
| AR_wasm32_unknown_unknown: llvm-ar | |
| run: bun run build | |
| - name: Test website | |
| working-directory: website | |
| run: bun run test | |
| - uses: actions/configure-pages@v5 | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| - uses: actions/upload-pages-artifact@v3 | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| with: | |
| path: website/dist | |
| deploy: | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |