name: Deploy Demo To GitHub Pages
"on":
workflow_dispatch:
push:
branches:
- main
- master
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install trunk
run: cargo install trunk --locked
- name: Install wasm-bindgen-cli
run: cargo install wasm-bindgen-cli --version 0.2.117 --locked
- name: Resolve GitHub Pages public URL
run: |
REPO_NAME="${GITHUB_REPOSITORY#*/}"
if [[ "$REPO_NAME" == *.github.io ]]; then
echo "PUBLIC_URL=/" >> "$GITHUB_ENV"
else
echo "PUBLIC_URL=/$REPO_NAME/" >> "$GITHUB_ENV"
fi
- name: Build example wasm modules
run: |
mkdir -p demo/pkg
cargo build --release --target wasm32-unknown-unknown --examples
for file in examples/*.rs; do
name="$(basename "$file" .rs)"
wasm="target/wasm32-unknown-unknown/release/examples/$name.wasm"
wasm-bindgen \
--target web \
--out-dir demo/pkg \
--out-name "$name" \
"$wasm"
done
- name: Build demo via trunk
run: |
cd demo
trunk build --release --public-url "$PUBLIC_URL"
- name: Copy runtime modules into dist
run: |
rm -rf demo/dist/pkg
cp -R demo/pkg demo/dist/pkg
touch demo/dist/.nojekyll
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: demo/dist
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4