name: Deploy WASM Playground (reusable)
on:
workflow_call:
inputs:
wasm-crate:
description: 'Cargo package to build with wasm-pack (e.g. unpdf-wasm)'
required: true
type: string
jobs:
build:
name: Build WASM + Pages
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-wasm-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-wasm-
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build WASM (web target for direct browser use)
run: wasm-pack build ${{ inputs.wasm-crate }} --target web --out-dir "${{ github.workspace }}/docs/pkg"
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/
retention-days: 1
deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4