name: Deploy, Install, Build & Run

on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: self-hosted

    steps:
      - uses: actions/checkout@v1

      - name: Delete old Dir & create a new one
        run: rm -rf /home/arthur/website && mkdir /home/arthur/website

  build:
    needs: deploy
    runs-on: self-hosted

    steps:
      - uses: actions/checkout@v1

      - name: Delete old Dir & create a new one
        run: rm -rf /home/arthur/website && mkdir /home/arthur/website

      - name: Deploy
        run: cp -r . /home/arthur/website

      - name: Install
        run: yarn install

      - name: Build
        run: yarn build-all

  run:
    needs: build
    runs-on: self-hosted

    steps:
      - name: Close old daemon
        run: pm2 delete next

      - name: Run
        run: pm2 start yarn --name "next" -- start