name: publish-github-pages

on:
  push:
    branches:
      - master
    paths:
      - 'docs/**'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  deploy:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-python@v2
        with:
          python-version: 3.x
      - run: pip install mkdocs-material

      # Build the mkdocs documentation in the docs/publish/docs dir. This will be at (/docs)
      # The -d (output) path is relative to the -f (source) path
      - name: Build docs site
        run: mkdocs build -f docs/docs/mkdocs.yml -d ../publish/docs

      - name: Generate Swagger UI
        uses: Legion2/swagger-ui-action@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          spec-file: ./docs/swagger/collections.yaml
          output: ./docs/publish/docs/swagger

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_branch: gh-pages
          publish_dir: ./docs/publish
          user_name: 'github-actions[bot]'
          user_email: 'github-actions[bot]@users.noreply.github.com'
