name: Build and Deploy 

on:
  push:
    branches:
      - master

env:
  ZOLA_VERSION: "0.19.2"
  HOST: ${{ secrets.SERVER_IP }}
  SSH_DEPLOY_USERNAME: ${{ secrets.DEPLOY_USERNAME }}
  SSH_REPO_KEY: ${{ secrets.SSH_REPO_KEY }}
  SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
  DEST_FOLDER: "/srv/www/cz/filiprojek/guitar"

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    container:
      image: git.0x45.cz/em/mixtape:240904

    steps:
      - name: Checkout repository
        run: git clone https://git.filiprojek.cz/fr/guitar.git /workspace/fr/guitar

      - name: Build Chordpro
        run: make pdf html songbook

      - name: Build zola
        run: zola build

      - name: Deploy
        run: |
          eval "$(ssh-agent -s)"
          echo "${SSH_DEPLOY_KEY}" | ssh-add -
          mkdir -p ~/.ssh/
          ssh-keyscan -H "${HOST}" >> ~/.ssh/known_hosts
          rsync -ra --delete-after public/* "${SSH_DEPLOY_USERNAME}@${HOST}:${DEST_FOLDER}"

