name: Deploy to GitHub Pages

on:
  push:
    branches: [ main ]

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    steps:
      - name: Checkout your repository using git
        uses: actions/checkout@v4
      - name: 🗳️ Setup pnpm cache
        uses: https://github.com/actions/cache@v3
        with:
          path: ${{ env.PNPM_STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ env.PNPM_CACHE_ID }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store
      - name: Install, build, and upload your site
        uses: withastro/action@v2
        # with:
          # path: . # The root location of your Astro project inside the repository. (optional)
          # node-version: 20 # The specific version of Node that should be used to build your site. Defaults to 20. (optional)
          # package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)

  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:

    - name: 🚀 Deploy files via SFTP
      uses: https://github.com/pressidium/lftp-mirror-action@v1
      with:
        host: ${{ secrets.FTP_HOST }}
        port: ${{ secrets.FTP_PORT || 21 }}
        user: ${{ secrets.FTP_USERNAME }}
        pass: ${{ secrets.FTP_PASSWORD }}
        onlyNewer: true
        parallel: '4'
        settings: 'sftp:auto-confirm=yes'
        localDir: 'public'
        remoteDir: '/share'
        options: '--verbose'
