name: Build and Deploy Hugo Site

on:
  push:
    branches:
      - main   # o master, o un altro branch

jobs:
  build-and-deploy:
    runs-on: usainbolt
    steps:

      # 1. Checkout del codice (scarica la repo usando un insieme di comandi prefatto)
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: true

      # 2. Build del sito
      - name: Build Hugo site
        run: |
          hugo --minify

      # 3. Deploy via rsync
      - name: Deploy to server
        env:
          SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}
        run: |
          mkdir -p ~/.ssh
              printf '%s\n' "${{ secrets.DEPLOY_PRIVATE_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -H 10.10.0.3 >> ~/.ssh/known_hosts
          rsync -avz --delete public/ proxi@10.10.0.3:/var/www/html

