name: build_and_publish

on:
  push:
    branches:
      - trunk
    tags:
      - v*
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: "0.85.0"
          extended: true

      - name: Install requirements
        working-directory: spiceaidocs
        run: |
          npm install

      - name: Build
        working-directory: spiceaidocs
        run: hugo --minify

      - name: Deploy
        if: ${{ github.event_name != 'pull_request' && startswith(github.ref, 'refs/tags/v') }}
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./spiceaidocs/public
          cname: docs.spiceai.org