This commit is contained in:
@@ -3,57 +3,78 @@ name: Deploy Website
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # change if your main branch is different
|
- rewrite-static # ✅ your current branch
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# --- 1. Checkout repository ---
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# ---- Debug info ----
|
# --- 2. Debug environment ---
|
||||||
- name: Debug secrets and env
|
- name: Debug secrets and environment
|
||||||
run: |
|
run: |
|
||||||
|
echo "🧩 Debugging environment"
|
||||||
|
echo "Branch: ${{ gitea.ref }}"
|
||||||
echo "Host: ${DEPLOY_HOST}"
|
echo "Host: ${DEPLOY_HOST}"
|
||||||
echo "User: ${DEPLOY_USER}"
|
echo "User: ${DEPLOY_USER}"
|
||||||
|
echo "Path: ${DEPLOY_PATH}"
|
||||||
echo "Port: ${DEPLOY_PORT:-22}"
|
echo "Port: ${DEPLOY_PORT:-22}"
|
||||||
|
|
||||||
if [ -n "${DEPLOY_KEY}" ]; then
|
if [ -n "${DEPLOY_KEY}" ]; then
|
||||||
echo "✅ DEPLOY_KEY appears set (length: ${#DEPLOY_KEY})"
|
echo "✅ DEPLOY_KEY is set (length: ${#DEPLOY_KEY})"
|
||||||
else
|
else
|
||||||
echo "❌ DEPLOY_KEY is empty!"
|
echo "❌ DEPLOY_KEY is missing!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||||
|
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||||
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
|
||||||
# ---- SSH setup ----
|
# --- 3. Set up SSH key ---
|
||||||
- name: Set up SSH key
|
- name: Set up SSH key
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -euxo pipefail
|
||||||
|
|
||||||
|
echo "🔑 Preparing SSH"
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
chmod 700 ~/.ssh
|
chmod 700 ~/.ssh
|
||||||
|
|
||||||
|
echo "🔍 Checking private key variable"
|
||||||
|
if [ -z "${DEPLOY_KEY}" ]; then
|
||||||
|
echo "❌ DEPLOY_KEY is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "📝 Writing SSH private key to ~/.ssh/id_rsa"
|
||||||
printf "%s" "${DEPLOY_KEY}" > ~/.ssh/id_rsa
|
printf "%s" "${DEPLOY_KEY}" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
echo "🔑 Testing ssh-keyscan on ${DEPLOY_HOST}:${DEPLOY_PORT:-22}"
|
echo "📡 Scanning SSH host key for ${DEPLOY_HOST}:${DEPLOY_PORT:-22}"
|
||||||
if ! ssh-keyscan -p "${DEPLOY_PORT:-22}" -H "${DEPLOY_HOST}" >> ~/.ssh/known_hosts 2>/dev/null; then
|
if ! ssh-keyscan -p "${DEPLOY_PORT:-22}" -H "${DEPLOY_HOST}" >> ~/.ssh/known_hosts 2>/dev/null; then
|
||||||
echo "⚠️ ssh-keyscan failed (host unreachable?)"
|
echo "⚠️ Warning: ssh-keyscan failed (host may be unreachable temporarily)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "✅ SSH key and known_hosts setup complete"
|
||||||
env:
|
env:
|
||||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
|
||||||
# ---- Deploy via rsync ----
|
# --- 4. Deploy website via rsync ---
|
||||||
- name: Deploy website via rsync
|
- name: Deploy website via rsync
|
||||||
run: |
|
run: |
|
||||||
echo "🚀 Deploying to ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH} (port ${DEPLOY_PORT:-22})"
|
echo "🚀 Starting deployment to ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH} (port ${DEPLOY_PORT:-22})"
|
||||||
rsync -avz -e "ssh -p ${DEPLOY_PORT:-22}" --delete ./ \
|
rsync -avz -e "ssh -p ${DEPLOY_PORT:-22}" --delete ./ \
|
||||||
${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}
|
${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}
|
||||||
|
|
||||||
|
echo "✅ Deployment completed successfully!"
|
||||||
env:
|
env:
|
||||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||||
|
|||||||
Reference in New Issue
Block a user