|
| 1 | +# Version: 3.0.0 |
| 2 | +# Last Updated: 2025-11-06 |
| 3 | + |
| 4 | +name: Deploy to Shared Hosting (FTP/S) |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# Permissions: Restrict what the workflow can do |
| 13 | +# - contents: read allows checkout of your repository code |
| 14 | +# This follows the principle of least privilege: only grant what's needed |
| 15 | +# For this workflow: We only need to read the code; we don't need write access |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +# Concurrency control: Ensures only one deployment runs at a time |
| 20 | +# - group: Logical grouping for this workflow (same across all project types) |
| 21 | +# - cancel-in-progress: Cancels any currently running deployment before starting a new one |
| 22 | +# This prevents multiple deployments from stacking up or conflicting if you push rapidly |
| 23 | +concurrency: |
| 24 | + group: shared-hosting-deploy |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + name: Build static site |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Setup pnpm |
| 36 | + uses: pnpm/action-setup@v4 |
| 37 | + with: |
| 38 | + version: 10 |
| 39 | + |
| 40 | + - name: Setup Node.js |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: 22 |
| 44 | + # Cache: Speed up dependency installation by caching pnpm's store directory |
| 45 | + # On subsequent runs, pnpm reuses cached dependencies instead of re-downloading them |
| 46 | + # Saves significant time and bandwidth, especially for workflows that run frequently |
| 47 | + cache: 'pnpm' |
| 48 | + |
| 49 | + # Install dependencies for the project |
| 50 | + # --no-frozen-lockfile: Allows pnpm to update the lock file if needed |
| 51 | + # By default, pnpm is strict and fails if pnpm-lock.yaml is missing or outdated |
| 52 | + # This flag lets pnpm regenerate the lock file, useful if it's not committed or is stale |
| 53 | + # Tradeoff: Less reproducible (lock file may differ between runs), but more flexible |
| 54 | + # Note: For production, consider using --frozen-lockfile for strict reproducibility |
| 55 | + - name: Install dependencies |
| 56 | + run: pnpm install --no-frozen-lockfile |
| 57 | + |
| 58 | + - name: Generate static site |
| 59 | + run: pnpm generate |
| 60 | + |
| 61 | + # Store the generated static site as an artifact for the deploy job |
| 62 | + # Artifacts are temporary files that persist between jobs in the same workflow run |
| 63 | + # This avoids rebuilding the site during the deploy job; we just reuse the pre-built output |
| 64 | + # Artifacts are automatically deleted after 90 days (configurable in GitHub settings) |
| 65 | + - name: Upload generated site as artifact |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: generated-output |
| 69 | + path: .output/public |
| 70 | + |
| 71 | + deploy: |
| 72 | + name: Upload to shared hosting |
| 73 | + needs: build |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - name: Download site artifact |
| 77 | + uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: generated-output |
| 80 | + path: generated-output |
| 81 | + |
| 82 | + # Deploy via SCP (Secure Copy Protocol) |
| 83 | + # SCP is more reliable than FTP/FTPS for shared hosting and works over SSH |
| 84 | + # Requires: SSH_HOST, SSH_USER, SSH_KEY (private key), and SSH_DEPLOY_PATH secrets |
| 85 | + - name: Deploy via SCP |
| 86 | + uses: garygrossgarten/github-action-scp@release |
| 87 | + with: |
| 88 | + host: ${{ secrets.SSH_HOST }} |
| 89 | + username: ${{ secrets.SSH_USERNAME }} |
| 90 | + privateKey: ${{ secrets.SSH_KEY }} |
| 91 | + local: generated-output/ |
| 92 | + remote: ${{ secrets.SSH_DEPLOY_PATH }} |
| 93 | + # recursive: Copies entire directory structure from local to remote |
| 94 | + # When true: Creates subdirectories on the server as needed |
| 95 | + # When false: Only copies files in the root directory (usually not what you want) |
| 96 | + recursive: true |
| 97 | + # Optional: Set to true to delete files on remote that don't exist locally |
| 98 | + # directoryMode: 0755 |
| 99 | + # fileMode: 0644 |
0 commit comments