name: github pages

on:
  push:
  workflow_dispatch:

# Lookup compatible version numbers at: https://github.com/lzanini/mdbook-katex/releases
env:
  mdbook-version: '0.4.40'
  katex-version: '0.9.0'
  linkcheck-version: '0.7.7'

jobs:
  deploy:
    runs-on: ubuntu-24.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v4

      - name: Fetch mdbook-katex
        uses: dsaltares/fetch-gh-release-asset@master
        with:
          repo: lzanini/mdbook-katex
          version: tags/${{env.katex-version}}-binaries
          file: "mdbook-katex-v${{env.katex-version}}-x86_64-unknown-linux-gnu.tar.gz"
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Install mdbook-katex
        run: tar -xvf mdbook-katex-v${{env.katex-version}}-x86_64-unknown-linux-gnu.tar.gz -C /usr/local/bin

      - name: Fetch mdbook-linkcheck
        uses: dsaltares/fetch-gh-release-asset@master
        with:
          repo: Michael-F-Bryan/mdbook-linkcheck
          version: tags/v${{env.linkcheck-version}}
          file: "mdbook-linkcheck.x86_64-unknown-linux-gnu.zip"
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Install mdbook-linkcheck
        run: |
          unzip mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -d /usr/local/bin
          chmod +x /usr/local/bin/mdbook-linkcheck

      - name: Setup mdBook
        uses: peaceiris/actions-mdbook@v2
        with:
          mdbook-version: ${{env.mdbook-version}}

      - run: mdbook build

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./book/html/
          cname: docs.tlsnotary.org
