91 lines
2.8 KiB
YAML
91 lines
2.8 KiB
YAML
name: Build and Deploy
|
||
|
||
on:
|
||
# Trigger the workflow every time you push to the `main` branch
|
||
# Using a different branch name? Replace `main` with your branch’s name
|
||
push:
|
||
branches: [ main ]
|
||
# Allows you to run this workflow manually from the Actions tab on GitHub.
|
||
workflow_dispatch:
|
||
|
||
# Allow this job to clone the repo and create a page deployment
|
||
permissions:
|
||
contents: read
|
||
pages: write
|
||
id-token: write
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup pnpm
|
||
uses: pnpm/action-setup@v2
|
||
|
||
- name: Free up disk space
|
||
run: |
|
||
# Display disk space before cleanup
|
||
df -h
|
||
|
||
# Remove large packages without using regex
|
||
sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox mono-runtime
|
||
sudo apt-get autoremove -y
|
||
|
||
# Remove large directories
|
||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache
|
||
|
||
# Clean Docker (if installed)
|
||
if command -v docker &> /dev/null; then
|
||
docker system prune -af
|
||
fi
|
||
|
||
# Display disk space after cleanup
|
||
df -h
|
||
|
||
- name: Install system dependencies
|
||
run: |
|
||
# Free up disk space
|
||
sudo rm -rf /var/lib/apt/lists/*
|
||
sudo apt-get clean
|
||
# Use compression to reduce download size
|
||
sudo apt-get update -o Acquire::CompressionTypes::Order::=gz
|
||
# Install minimal dependencies
|
||
sudo apt-get install -y --no-install-recommends rsync build-essential libvips-dev
|
||
# Clean up to save space
|
||
sudo apt-get clean
|
||
sudo rm -rf /var/lib/apt/lists/*
|
||
|
||
- name: Setup SSH key
|
||
run: |
|
||
mkdir -p ~/.ssh
|
||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||
chmod 600 ~/.ssh/id_rsa
|
||
eval $(ssh-agent -s)
|
||
ssh-add ~/.ssh/id_rsa
|
||
|
||
- name: Add server to known_hosts
|
||
run: ssh-keyscan ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
|
||
|
||
- name: Install dependencies
|
||
run: pnpm install
|
||
|
||
- name: Build Astro site
|
||
run: |
|
||
echo "Attempting to build with Sharp..."
|
||
if pnpm run build; then
|
||
echo "Build with Sharp successful!"
|
||
else
|
||
echo "Build with Sharp failed, falling back to passthrough image service..."
|
||
# Copy the CI config to use the passthrough image service
|
||
cp astro.config.ci.mjs astro.config.mjs
|
||
# Clean the previous failed build
|
||
rm -rf dist
|
||
# Try building again with the passthrough config
|
||
pnpm run build
|
||
fi
|
||
|
||
- name: Deploy to server
|
||
run: rsync -avzP ./dist/ root@${{ secrets.SERVER_IP }}:/var/www/html/
|