website/.github/workflows/default.yaml

75 lines
2.1 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 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 19:52:43 +02:00
- name: 🔑 Set up SSH Key
run: |
2024-04-07 20:11:47 +02:00
eval `ssh-agent -s`
2024-04-07 19:52:43 +02:00
echo "$SSH_PRIVATE_KEY" > /tmp/id_rsa
chmod 600 /tmp/id_rsa
ssh-add /tmp/id_rsa
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
2024-04-06 15:33:22 +02:00
2024-04-07 19:52:43 +02:00
- name: 🚀 Deploy Changed Files via rsync
run: |
2024-04-07 20:22:50 +02:00
rsync -avz -e "ssh -p ${SSH_PORT}" ./dist/ ${SSH_USER}@${SSH_HOST}:${REMOTE_DIR}
2024-04-07 20:27:20 +02:00
env:
SSH_HOST: ${{ vars.SSH_HOST }}
SSH_PORT: ${{ vars.SSH_PORT }}
SSH_USER: ${{ vars.SSH_USER }}
REMOTE_DIR: ${{ vars.REMOTE_DIR }}