name: Hugo deployment test

on:
  push:
    branches-ignore:
    - gh-pages

jobs:
  build-deploy:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@master

    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2.2.2
      with:
        hugo-version: '0.59.1'
        extended: true

    - name: Build GitHub Pages
      run: hugo --minify -DEFb=https://msfjarvis.github.io/msfjarvis.website

    - name: Deploy to GitHub pages
      uses: docker://peaceiris/gh-pages:latest
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        PUBLISH_BRANCH: gh-pages
        PUBLISH_DIR: ./public

    - name: Audit live URL
      uses: docker://jakejarvis/lighthouse-action:latest
      with:
        url: 'https://msfjarvis.github.io/msfjarvis.website/'

    - name: Upload results as an artifact
      uses: actions/upload-artifact@master
      with:
        name: report
        path: './report'

    - name: Build staging
      run: hugo --minify -DEFb=https://staging.msfjarvis.website

    - name: Deploy to staging
      run: source $GITHUB_WORKSPACE/ci/deploy.sh
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
        SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }}
        SERVER_DESTINATION: ${{ secrets.SERVER_DESTINATION }}
        SSH_PORT: ${{ secrets.SSH_PORT }}

    - name: Build prod
      run: hugo --minify

    - name: Deploy to prod
      run: source $GITHUB_WORKSPACE/ci/deploy.sh
      env:
        ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
        SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }}
        SERVER_DESTINATION: ${{ secrets.SERVER_DESTINATION }}
        SSH_PORT: ${{ secrets.SSH_PORT }}
