# Copyright 2020-2022 David Sherret. All rights reserved. MIT license.
name: Website
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false

      - uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - uses: denoland/setup-deno@v1

      - name: Install playground dependencies
        run: (cd website/playground && npm ci --legacy-peer-deps)

      - name: Build playground
        run: npm run build --prefix website/playground

      - name: Build website
        run: (cd website && deno task build)

      - name: Deploy
        if: github.ref == 'refs/heads/main'
        uses: JamesIves/github-pages-deploy-action@releases/v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: website/_site
