name: Deploy Rust Docs to GitHub Pages

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Generate documentation
        run: cargo doc --no-deps

      - name: Add redirect
        run: echo '<meta http-equiv="refresh" content="0;url=cas/index.html">' > target/doc/index.html

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.TOKEN }}
          publish_dir: ./target/doc
          publish_branch: gh-pages