name: Docs

on:
  pull_request:
    paths:
      - 'www'
      - '*.md'
  push:
    branches:
      - master

jobs:
  build:
    name: Build Docs
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Install Task
        uses: go-task/setup-task@v1
      - name: Build site
        run: task docs

  build-and-release:
    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
    name: Build and Release Docs
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Install Task
        uses: go-task/setup-task@v1
      - name: Build site
        run: task docs
      - name: Upload static files as artifact
        uses: actions/upload-pages-artifact@v4
        with:
          path: www/public
      - name: Deploy to GitHub Pages
        uses: actions/deploy-pages@v4
