name: Website

on:
  push:
    branches: [main]
    paths:
      - .github/workflows/website.yml
      - docs/**
      - website/**

  pull_request:
    branches: [main]
    paths:
      - .github/workflows/website.yml
      - docs/**
      - website/**

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: "16"
          cache: yarn
          cache-dependency-path: ./website/yarn.lock

      - uses: actions/cache@v3
        with:
          path: website/.docusaurus
          key: docusaurus-main-${{ github.sha }}
          restore-keys: |
            docusaurus-main-

      - name: Install
        working-directory: website
        run: yarn install --frozen-lockfile

      - name: Build
        working-directory: website
        run: yarn build

      - name: Deploy
        if: github.ref == 'refs/heads/main'
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: website/build