name: Publish Site
on:
  pull_request:
    paths:
      - docs/**
  push:
    branches:
      - main
  schedule:
   - cron: 0 20 * * *

permissions:
  contents: write

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: '0.111.0'
          extended: true
      - name: Install deps
        run: |
          npm install postcss-cli
          npm install autoprefixer
      - name: Build package docs
        run: |
          make BASE_URL=https://rancher.github.io/elemental-toolkit build-docs
      - name: Deploy
        if: github.ref == 'refs/heads/main' && github.event_name == 'push'
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          branch: gh-pages
          folder: public

