website/.github/workflows/default.yaml

76 lines
2.3 KiB
YAML
Raw Normal View History

2024-04-06 15:33:22 +02:00
name: Deploy to SFTP Server
2024-04-03 16:18:30 +02:00
on:
push:
2024-04-06 15:33:22 +02:00
branches: [main]
2024-04-03 16:18:30 +02:00
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
2024-04-03 16:48:10 +02:00
env:
2024-04-06 15:33:22 +02:00
RUNNER_TOOL_CACHE: '/toolcache'
2024-04-03 16:35:52 +02:00
runs-on: ubuntu-latest
2024-04-06 16:43:38 +02:00
container: git.max-richter.dev/max/website:latest
2024-04-03 16:18:30 +02:00
steps:
2024-04-07 21:02:09 +02:00
2024-04-07 20:24:27 +02:00
- name: 🔄 Checkout code
uses: actions/checkout@v3
2024-04-06 15:33:22 +02:00
- name: 🔢 Calculate cache IDs
2024-04-03 17:20:56 +02:00
run: |
2024-04-06 15:33:22 +02:00
# Calculate cache IDs for Git LFS and PNPM
2024-04-03 17:20:56 +02:00
git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
2024-04-06 15:33:22 +02:00
LFS_CACHE_ID=$(cat .lfs-assets-id | md5sum)-v1
PNPM_CACHE_ID=$(cat pnpm-lock.yaml | md5sum)-v1
2024-04-03 17:20:56 +02:00
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
2024-04-03 17:17:10 +02:00
2024-04-06 15:33:22 +02:00
- name: 🗄️ Cache Git LFS objects
uses: actions/cache@v4
2024-04-03 17:17:10 +02:00
with:
2024-04-06 15:33:22 +02:00
path: .git/lfs
2024-04-03 17:20:56 +02:00
key: ${{ runner.os }}-lfs-${{ env.LFS_CACHE_ID }}
2024-04-03 16:35:52 +02:00
2024-04-06 15:33:22 +02:00
- name: 🛠️ Cache PNPM dependencies
uses: actions/cache@v4
2024-04-03 16:18:30 +02:00
with:
2024-04-06 16:00:15 +02:00
path: ${{ env.PNPM_STORE_PATH }}
2024-04-03 16:48:10 +02:00
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
2024-04-03 16:35:52 +02:00
2024-04-06 16:33:30 +02:00
- name: 📷 Cache Astro Images
uses: actions/cache@v4
with:
path: node_modules/.astro
key: ${{ runner.os }}-astro-v1
2024-04-06 15:33:22 +02:00
- name: 🔄 Pull Git LFS files
2024-04-03 20:07:32 +02:00
run: git lfs pull
2024-04-06 15:33:22 +02:00
- name: 🏗️ Build site
run: |
# Install dependencies, build, and generate site output
pnpm i && pnpm build
2024-04-03 16:18:30 +02:00
2024-04-07 21:39:23 +02:00
- name: 🔑 Configure rclone
run: |
echo "$SSH_PRIVATE_KEY" > /tmp/id_rsa
chmod 600 /tmp/id_rsa
mkdir -p ~/.config/rclone
2024-04-07 21:56:14 +02:00
echo -e "[sftp-remote]\ntype = sftp\nhost = ${SSH_HOST}\nuser = ${SSH_USER}\nport = ${SSH_PORT}\nkey_file = /tmp/id_rsa" > ~/.config/rclone/rclone.conf
2024-04-07 21:39:23 +02:00
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: |
2024-04-07 21:56:14 +02:00
rclone sync --update --progress --stats-one-line ./dist/ sftp-remote:${REMOTE_DIR} --transfers 4
2024-04-07 21:39:23 +02:00
env:
REMOTE_DIR: ${{ vars.REMOTE_DIR }}