fix: switch plugin deploy from git-pull to rsync

The git-pull deploy failed silently because Hostinger doesn't have SSH
keys to access the private GitHub repo. Switched to rsync from the GH
Actions runner (same proven approach as the theme repo), which avoids
needing git access on the server entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Terence Ong
2026-04-08 10:34:17 +07:00
parent 672cdacd60
commit c13919c217

View File

@@ -67,56 +67,52 @@ jobs:
# Normal push (fast-forward). # Normal push (fast-forward).
git push origin deploy git push origin deploy
# -- Deploy to Hostinger via SSH -- # -- Deploy to Hostinger via rsync --
# SSH into Hostinger and git pull the deploy branch directly into # Rsync the deploy branch content from the GH Actions runner directly
# the correct plugin directory (peptide-news-plugin). # to the plugin directory on Hostinger (avoids needing git access on server).
deploy: deploy:
name: Deploy to Hostinger name: Deploy to Hostinger
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: sync-deploy-branch needs: sync-deploy-branch
environment: production environment: production
steps: steps:
- name: Pull deploy branch on Hostinger - name: Checkout deploy branch
uses: appleboy/ssh-action@v1 uses: actions/checkout@v4
with: with:
host: ${{ secrets.SSH_HOST }} ref: deploy
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Setup SSH key
port: ${{ secrets.SSH_PORT }} run: |
script: |
# Ensure GitHub host key is trusted (one-time setup).
mkdir -p ~/.ssh mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
PLUGIN_DIR="$HOME/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-news-plugin" - name: Deploy via rsync
REPO_URL="git@github.com:peptiderepo/peptide-news-plugin.git" run: |
rsync -avz --delete \
if [ -d "$PLUGIN_DIR/.git" ]; then --exclude='.git' \
# Existing clone -- just pull latest. --exclude='.github' \
cd "$PLUGIN_DIR" -e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no" \
git fetch origin deploy ./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-news-plugin/
git reset --hard origin/deploy
else
# First deploy -- clone the deploy branch.
rm -rf "$PLUGIN_DIR"
git clone -b deploy "$REPO_URL" "$PLUGIN_DIR"
fi
echo "Deployed to $PLUGIN_DIR"
ls -la "$PLUGIN_DIR"
- name: Purge LiteSpeed Cache - name: Purge LiteSpeed Cache
if: success() if: success()
run: | run: |
# Trigger a cache purge via the WordPress REST API. ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no \
if [ -n "${{ secrets.WP_APP_PASSWORD }}" ]; then ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'ENDSSH'
curl -s -X POST \ CACHE_DIR="/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html/wp-content/litespeed"
-u "${{ secrets.WP_ADMIN_USER }}:${{ secrets.WP_APP_PASSWORD }}" \ if [ -d "$CACHE_DIR" ]; then
"${{ secrets.WP_SITE_URL }}/wp-json/peptide-news/v1/cache-purge" \ rm -rf "$CACHE_DIR"/*
--max-time 15 || echo "Cache purge skipped (endpoint not available)" echo "LiteSpeed cache purged."
else
echo "No WP_APP_PASSWORD set -- skipping remote cache purge."
fi fi
touch "/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html/.lscache_purge" 2>/dev/null || true
echo "Cache purge signal sent."
ENDSSH
- name: Cleanup
if: always()
run: rm -f ~/.ssh/deploy_key
- name: Deploy summary - name: Deploy summary
run: | run: |
@@ -124,5 +120,5 @@ jobs:
echo "" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY echo "- **Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Method:** SSH direct deploy (git pull on Hostinger)" >> $GITHUB_STEP_SUMMARY echo "- **Method:** rsync from deploy branch to Hostinger" >> $GITHUB_STEP_SUMMARY
echo "- **Deployed to:** ${{ secrets.WP_SITE_URL || 'peptiderepo.com' }}" >> $GITHUB_STEP_SUMMARY echo "- **Deployed to:** ${{ secrets.WP_SITE_URL || 'peptiderepo.com' }}" >> $GITHUB_STEP_SUMMARY