name: Docs

on: [push]

jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Install x11 dependencies for Kludgine
        run: |
          sudo apt-get update -y -qq
          sudo add-apt-repository ppa:oibaf/graphics-drivers -y
          sudo apt-get update
          sudo apt-get install -y \
            libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers libdbus-1-dev pkg-config

      - uses: dtolnay/rust-toolchain@stable

      - name: Generate Docs
        run: |
          cargo doc --no-deps --all-features --workspace

      - name: Deploy
        uses: khonsulabs/sync-to-dossier@main
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/')
        with:
          url: ${{ secrets.DOSSIER_URL }}
          api-key-id: ${{ secrets.DOSSIER_API_KEY_ID }}
          api-key: ${{ secrets.DOSSIER_API_KEY }}
          project: cushy
          from: target/doc/
          to: /${{ github.ref_name }}/docs

  guide:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: dtolnay/rust-toolchain@stable

      - name: Install x11 dependencies for Kludgine
        run: |
          sudo apt-get update -y -qq
          sudo add-apt-repository ppa:oibaf/graphics-drivers -y
          sudo apt-get update
          sudo apt-get install -y \
            libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers libdbus-1-dev pkg-config

      - name: Download mdbook
        run: |
          curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.36/mdbook-v0.4.36-x86_64-unknown-linux-gnu.tar.gz | tar -xz

      - name: Install mdbook-variables
        run: |
          cargo install mdbook-variables

      - name: Regenerate Example Images
        run: |
          CAPTURE=1 cargo test -p cushy --examples --all-features -r

      - name: Regenerate Guide Example Images
        run: |
          CAPTURE=1 cargo test -p guide-examples --examples -r

      - name: Build Guide
        run: |
          ./mdbook build guide

      - name: Deploy
        uses: khonsulabs/sync-to-dossier@main
        if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/')
        with:
          url: ${{ secrets.DOSSIER_URL }}
          api-key-id: ${{ secrets.DOSSIER_API_KEY_ID }}
          api-key: ${{ secrets.DOSSIER_API_KEY }}
          project: cushy
          from: target/guide/
          to: /${{ github.ref_name }}/guide