name: Build

on: [push, pull_request]

jobs:
    build:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node-version: [12.x]
        steps:
            - name: Checkout
              uses: actions/checkout@v2
              with:
                  persist-credentials: false
            - name: Reconfigure git to use HTTP authentication
              run: >
                  git config --global url."https://github.com/".insteadOf
                  ssh://git@github.com/
            - name: Setup Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node-version }}

            - name: Cache Node Modules
              uses: actions/cache@v1
              with:
                  path: .cache
                  key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}

            - run: npm ci
            - run: npm run validate
            - run: npm run build

            - name: Deploy on push to main branch
              if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
              uses: peaceiris/actions-gh-pages@v3
              with:
                  github_token: ${{ secrets.GITHUB_TOKEN }}
                  publish_branch: gh-pages
                  publish_dir: ./public
