Files
CI-CD/前端/.gitea/workflows/deploy.yml
T
2026-06-20 21:54:12 +08:00

54 lines
1.4 KiB
YAML

name: Deploy Static Frontend
on:
push:
branches:
- main
paths:
- '前端/**' # 🌟 只有“前端”文件夹下的东西变动时才触发
jobs:
deploy:
runs-on: ci-base
steps:
- name: Checkout code
uses: http://192.168.31.185:3002/actions/checkout@v4
- name: Deploy via RSYNC
run: |
set -e
SERVER_HOST="${{ secrets.SSH_HOST }}"
SERVER_USER="${{ secrets.SSH_USER }}"
SERVER_PORT="${{ secrets.SSH_PORT }}"
TARGET_DIR="${{ secrets.TARGET_DIR }}"
: ${SERVER_HOST:="192.168.31.185"}
: ${SERVER_USER:="shuai"}
: ${SERVER_PORT:="2222"}
: ${TARGET_DIR:="/data/apps/ci-cd/frontend"}
echo "Deploy to ${SERVER_USER}@${SERVER_HOST}:${TARGET_DIR}"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s\n' "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "${SERVER_PORT}" -H "${SERVER_HOST}" >> ~/.ssh/known_hosts
ssh -i ~/.ssh/id_ed25519 -p "${SERVER_PORT}" \
"${SERVER_USER}@${SERVER_HOST}" \
"mkdir -p ${TARGET_DIR}"
rsync -avz --delete \
-e "ssh -i ~/.ssh/id_ed25519 -p ${SERVER_PORT}" \
--exclude ".git" \
--exclude ".gitea" \
./ \
"${SERVER_USER}@${SERVER_HOST}:${TARGET_DIR}/"
echo "Deploy success"