name: Deploy

on:
  push:
    branches: [main, master]

jobs:
  deploy:
    runs-on: self-hosted
    steps:
      - name: Clone
        run: |
          sudo rm -rf /tmp/deploy-val-blog
          git clone "https://gch3n:${{ secrets.GITEA_TOKEN }}@git.gch3n.online/gch3n/val-blog.git" /tmp/deploy-val-blog

      - name: Build with Hugo
        run: |
          cd /tmp/deploy-val-blog
          docker run --rm -v /tmp/deploy-val-blog:/src -w /src klakegg/hugo:ext-alpine --minify

      - name: Deploy
        run: |
          sudo mkdir -p /var/www/val-blog
          sudo cp -r /tmp/deploy-val-blog/public/* /var/www/val-blog/
          sudo chown -R caddy:caddy /var/www/val-blog
          sudo rm -rf /tmp/deploy-val-blog

      - name: Done
        run: echo "✓ Deployed to gch3n.online/val-blog/"
