name: Site

on:
  workflow_dispatch: {}
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
      with:
        targets: wasm32-unknown-unknown
    - uses: peaceiris/actions-mdbook@v1
      with:
        mdbook-version: latest
    - run: npm install
      working-directory: crates/rune-wasm
    - run: npm run build
      working-directory: crates/rune-wasm
    - run: cargo run --manifest-path tools/site/Cargo.toml -- -r site build -o target/site
      env:
        ZOLA_URL: "https://github.com/getzola/zola/releases/download/v0.17.2/zola-v0.17.2-x86_64-unknown-linux-gnu.tar.gz"
    - run: cargo run --bin rune -- doc --output target/site/docs
      env:
        RUST_LOG: rune=info
    - run: mdbook build -d ../target/site/book book
    - uses: dtolnay/rust-toolchain@nightly
    - run: cargo +nightly doc -p rune --all-features
      env:
        RUST_LOG: rune=info
        RUSTFLAGS: --cfg rune_docsrs
        RUSTDOCFLAGS: --cfg rune_docsrs
    - run: mv target/doc target/site/api
    - uses: peaceiris/actions-gh-pages@v3
      with:
        deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        external_repository: rune-rs/rune-rs.github.io
        publish_branch: main
        publish_dir: target/site
