gitea action to deploy with rsync w ssh key
Some checks failed
Deploy website to VPS / build-and-deploy (push) Failing after 2s
Some checks failed
Deploy website to VPS / build-and-deploy (push) Failing after 2s
This commit is contained in:
81
.gitea/workflows/depoly.yaml
Normal file
81
.gitea/workflows/depoly.yaml
Normal file
@@ -0,0 +1,81 @@
|
||||
name: Deploy website to VPS
|
||||
|
||||
env:
|
||||
NODE_VERSION: '20'
|
||||
HUGO_VERSION: '0.121.0' # Fallback version
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['main']
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest # This maps to your node:20-alpine runner
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install System Dependencies
|
||||
run: |
|
||||
apk add --no-cache rsync openssh-client bash git
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
|
||||
- name: Setup pnpm
|
||||
if: hashFiles('package.json') != ''
|
||||
uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Get Hugo Version
|
||||
run: |
|
||||
if [ -f "hugoblox.yaml" ]; then
|
||||
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\"")
|
||||
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
if [ -f "package.json" ]; then
|
||||
pnpm install --no-frozen-lockfile || npm install
|
||||
fi
|
||||
|
||||
- name: Setup Hugo
|
||||
uses: peaceiris/actions-hugo@v3
|
||||
with:
|
||||
hugo-version: ${{ env.HUGO_VERSION }}
|
||||
extended: true
|
||||
|
||||
- name: Build with Hugo
|
||||
run: |
|
||||
# Use your actual domain here
|
||||
hugo --minify --baseURL "https://ejs.cam/"
|
||||
|
||||
- name: Generate Pagefind search index
|
||||
run: |
|
||||
if [ -f "package.json" ] && grep -q "pagefind" package.json; then
|
||||
pnpm dlx pagefind --source "public" || npx pagefind --source "public"
|
||||
fi
|
||||
|
||||
- name: Deploy via Rsync
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
run: |
|
||||
# Setup SSH
|
||||
mkdir -p ~/.ssh
|
||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
|
||||
# Scan host key to prevent MITM prompts
|
||||
ssh-keyscan -p ${{ secrets.REMOTE_PORT }} ${{ secrets.REMOTE_HOST }} >> ~/.ssh/known_hosts
|
||||
|
||||
# Sync files
|
||||
# --delete ensures old files are removed from /var/www
|
||||
rsync -avz --delete \
|
||||
-e "ssh -p ${{ secrets.REMOTE_PORT }}" \
|
||||
./public/ \
|
||||
${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:/var/www/
|
||||
Reference in New Issue
Block a user