name: Deploy Website on: push: branches: - rewrite-static # ✅ your current branch jobs: deploy: runs-on: self-hosted steps: # --- 1. Checkout repository --- - name: Checkout repository uses: actions/checkout@v3 # --- 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 is set (length: ${#DEPLOY_KEY})" else 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 }} # --- 3. Set up SSH key --- - name: Set up SSH key run: | 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 "📡 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 "⚠️ 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 }} # --- 4. Deploy website via rsync --- - name: Deploy website via rsync run: | 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 }} DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}