This commit is contained in:
@@ -3,57 +3,78 @@ name: Deploy Website
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # change if your main branch is different
|
||||
- rewrite-static # ✅ your current branch
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: self-hosted
|
||||
|
||||
steps:
|
||||
# --- 1. Checkout repository ---
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# ---- Debug info ----
|
||||
- name: Debug secrets and env
|
||||
# --- 2. Debug environment ---
|
||||
- name: Debug secrets and environment
|
||||
run: |
|
||||
echo "🧩 Debugging environment"
|
||||
echo "Branch: ${{ gitea.ref }}"
|
||||
echo "Host: ${DEPLOY_HOST}"
|
||||
echo "User: ${DEPLOY_USER}"
|
||||
echo "Path: ${DEPLOY_PATH}"
|
||||
echo "Port: ${DEPLOY_PORT:-22}"
|
||||
|
||||
if [ -n "${DEPLOY_KEY}" ]; then
|
||||
echo "✅ DEPLOY_KEY appears set (length: ${#DEPLOY_KEY})"
|
||||
echo "✅ DEPLOY_KEY is set (length: ${#DEPLOY_KEY})"
|
||||
else
|
||||
echo "❌ DEPLOY_KEY is empty!"
|
||||
echo "❌ DEPLOY_KEY is missing!"
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||
|
||||
# ---- SSH setup ----
|
||||
# --- 3. Set up SSH key ---
|
||||
- name: Set up SSH key
|
||||
run: |
|
||||
set -e
|
||||
set -euxo pipefail
|
||||
|
||||
echo "🔑 Preparing SSH"
|
||||
mkdir -p ~/.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
|
||||
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
|
||||
echo "⚠️ ssh-keyscan failed (host unreachable?)"
|
||||
echo "⚠️ Warning: ssh-keyscan failed (host may be unreachable temporarily)"
|
||||
fi
|
||||
|
||||
echo "✅ SSH key and known_hosts setup complete"
|
||||
env:
|
||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
||||
|
||||
# ---- Deploy via rsync ----
|
||||
# --- 4. Deploy website via rsync ---
|
||||
- name: Deploy website via rsync
|
||||
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 ./ \
|
||||
${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}
|
||||
|
||||
echo "✅ Deployment completed successfully!"
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
|
||||
Reference in New Issue
Block a user