name: Deploy

concurrency:
  group: deploy-production
  cancel-in-progress: true

on:
  workflow_dispatch:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment:
      name: bbaovanc.com
      url: https://bbaovanc.com
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: latest
          extended: true

      - name: Build
        run: hugo --printI18nWarnings --printPathWarnings

      - name: Compress
        run: |
          time sudo ./compress.sh

      - name: Setup SSH
        uses: kielabokkie/ssh-key-and-known-hosts-action@v1
        with:
          ssh-private-key: ${{ secrets.DEPLOY_SSH_KEY }}
          ssh-host: srv.bbaovanc.com
          ssh-port: 2222

      - name: Upload
        uses: up9cloud/action-rsync@v1
        env:
          HOST: srv.bbaovanc.com
          USER: droneci
          PORT: 2222
          SOURCE: public/
          MODE: push
          VERBOSE: true
          KEY: ${{secrets.DEPLOY_SSH_KEY}}
          TARGET: /var/www/bbaovanc.com/public/
          ARGS: -avPzc --delete-delay --exclude=/.git/ --exclude=/.github/
