90 lines
3.0 KiB
YAML
90 lines
3.0 KiB
YAML
name: Deploy to SFTP Server
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
permissions:
|
|
contents: read
|
|
pages: write
|
|
id-token: write
|
|
|
|
jobs:
|
|
build:
|
|
env:
|
|
RUNNER_TOOL_CACHE: '/toolcache'
|
|
runs-on: ubuntu-latest
|
|
container: git.max-richter.dev/max/website:latest
|
|
steps:
|
|
|
|
- name: 🔄 Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: 🔢 Calculate cache IDs
|
|
run: |
|
|
# Calculate cache IDs for Git LFS and PNPM
|
|
git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
|
|
LFS_CACHE_ID=$(cat .lfs-assets-id | md5sum)-v1
|
|
PNPM_CACHE_ID=$(cat pnpm-lock.yaml | md5sum)-v1
|
|
echo "LFS_CACHE_ID=$LFS_CACHE_ID" >> $GITHUB_ENV
|
|
echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_ENV
|
|
echo "PNPM_CACHE_ID=$PNPM_CACHE_ID" >> $GITHUB_ENV
|
|
|
|
- name: 🗄️ Cache Git LFS objects
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: .git/lfs
|
|
key: ${{ runner.os }}-lfs-${{ env.LFS_CACHE_ID }}
|
|
|
|
- name: 🛠️ Cache PNPM dependencies
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ env.PNPM_STORE_PATH }}
|
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
|
|
- name: 📷 Cache Astro Images
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: node_modules/.astro
|
|
key: ${{ runner.os }}-astro-v1
|
|
|
|
- name: 🔄 Pull Git LFS files
|
|
run: git lfs pull
|
|
|
|
- name: 🔧 Increase file descriptor limits
|
|
run: |
|
|
echo "Current file descriptor limits:"
|
|
ulimit -n
|
|
echo "Increasing file descriptor limits..."
|
|
ulimit -n 65536
|
|
echo "New file descriptor limits:"
|
|
ulimit -n
|
|
|
|
- name: 🏗️ Build site
|
|
run: |
|
|
# Build with NODE_OPTIONS to increase memory limits and avoid watching files
|
|
export NODE_OPTIONS="--max-old-space-size=4096 --no-warnings --use-inlining-snapshots"
|
|
# Astro-specific optimizations to avoid file watching
|
|
pnpm i && NODE_ENV=production ASTRO_DISABLE_HMR=true pnpm build
|
|
|
|
- name: 🔑 Configure rclone
|
|
run: |
|
|
echo "$SSH_PRIVATE_KEY" > /tmp/id_rsa
|
|
chmod 600 /tmp/id_rsa
|
|
mkdir -p ~/.config/rclone
|
|
echo -e "[sftp-remote]\ntype = sftp\nhost = ${SSH_HOST}\nuser = ${SSH_USER}\nport = ${SSH_PORT}\nkey_file = /tmp/id_rsa" > ~/.config/rclone/rclone.conf
|
|
env:
|
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
SSH_HOST: ${{ vars.SSH_HOST }}
|
|
SSH_PORT: ${{ vars.SSH_PORT }}
|
|
SSH_USER: ${{ vars.SSH_USER }}
|
|
|
|
- name: 🚀 Deploy Changed Files via rclone
|
|
run: |
|
|
echo "Uploading _astro assets"
|
|
rclone sync --update -v --progress --size-only --stats 2s --stats-one-line ./dist/_astro sftp-remote:${REMOTE_DIR}/_astro --transfers 4
|
|
echo "Uploading the rest"
|
|
rclone sync --update -v --progress --exclude _astro/** --stats 2s --stats-one-line ./dist/ sftp-remote:${REMOTE_DIR} --transfers 4
|
|
env:
|
|
REMOTE_DIR: ${{ vars.REMOTE_DIR }}
|