name: docs

on:
  push:
    branches:
      - 'master'
    tags:
      - 'v*'
    paths:
      - '.github/workflows/docs.yml'
      - 'docs/**'
      - 'CHANGELOG.md'
      - 'mkdocs.yml'
  pull_request:
    branches:
      - 'master'
    paths:
      - '.github/workflows/docs.yml'
      - 'docs/**'
      - 'CHANGELOG.md'
      - 'mkdocs.yml'

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
        with:
          version: latest
      -
        name: Build docs
        uses: docker/bake-action@v1
        with:
          targets: docs
      -
        name: Check GitHub Pages status
        uses: crazy-max/ghaction-github-status@v2
        with:
          pages_threshold: major_outage
      -
        name: Deploy
        if: github.event_name != 'pull_request'
        uses: crazy-max/ghaction-github-pages@v2
        with:
          target_branch: gh-pages
          build_dir: site
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
