name: GitHub Pages

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main
    - release/*

jobs:
  docs-build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup nodejs
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Test docs build
        run: |
          cd website
          npm ci
          npm run build
      - name: Prepare ssh key
        uses: webfactory/ssh-agent@v0.5.0
        if: ${{ github.event_name == 'push' }}
        with:
          ssh-private-key: ${{ secrets.GH_PAGES_KEY }}
      - name: Publish to GitHub Pages
        if: ${{ github.event_name == 'push' }}
        env:
          GIT_USER: ${{ secrets.GH_PAGES_USERNAME }}
          USE_SSH: true
        run: |
          git config --global user.email "actions@github.com"
          git config --global user.name "GitHub Actions"
          cd website
          npm run deploy
