name: Deploy to trailsiq.com

# Fires on every push to main (which happens when a PR is merged), plus a
# manual "Run workflow" button in the Actions tab for on-demand redeploys.
on:
  push:
    branches: [ main ]
  workflow_dispatch:

# Cancel any earlier in-flight deploy if a new push lands — we only ever want
# the latest main to be live.
concurrency:
  group: deploy-prod
  cancel-in-progress: true

# Opt in to Node.js 24 for JS-based actions — silences the Node 20 deprecation
# warning from actions/checkout etc. before the June 2026 cutoff.
env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up SSH for rsync
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan -H "${{ secrets.DEPLOY_HOST }}" >> ~/.ssh/known_hosts

      - name: Rsync to server
        run: |
          rsync -rlptDz --delete \
            --exclude='.git/' \
            --exclude='.github/' \
            --exclude='.gitignore' \
            --exclude='.DS_Store' \
            --exclude='node_modules/' \
            --exclude='*.log' \
            ./ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/"
