Hostinger's git pull fails with divergent branches when force-pushing orphan commits. Switch to a linear commit strategy: checkout the existing deploy branch, sync plugin files from main, and push normally. This keeps Hostinger's git pull fast-forward compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
3.4 KiB
YAML
97 lines
3.4 KiB
YAML
name: Deploy to WordPress
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
# Cancel previous deploys if a new push arrives while one is running.
|
|
concurrency:
|
|
group: deploy-production
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# ── Run tests first ──────────────────────────────────────────────
|
|
test:
|
|
name: Pre-deploy tests
|
|
uses: ./.github/workflows/ci.yml
|
|
|
|
# ── Push clean plugin files to the deploy branch ─────────────────
|
|
# Hostinger's built-in GIT integration watches the `deploy` branch
|
|
# and auto-pulls via webhook when it changes. This avoids the
|
|
# firewall issues with push-based SCP/FTP from GitHub Actions.
|
|
deploy:
|
|
name: Update deploy branch
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
environment: production
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Sync deploy branch
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
# Fetch the remote deploy branch (may not exist on first run).
|
|
git fetch origin deploy:deploy 2>/dev/null || true
|
|
|
|
# If deploy branch exists, check it out; otherwise create it.
|
|
if git rev-parse --verify deploy >/dev/null 2>&1; then
|
|
git checkout deploy
|
|
else
|
|
git checkout --orphan deploy
|
|
git rm -rf --cached . > /dev/null 2>&1 || true
|
|
fi
|
|
|
|
# Remove all tracked files so we start clean each time.
|
|
git rm -rf . > /dev/null 2>&1 || true
|
|
|
|
# Checkout only the plugin runtime files from main.
|
|
git checkout main -- \
|
|
admin/ \
|
|
includes/ \
|
|
languages/ \
|
|
public/ \
|
|
peptide-news-plugin.php
|
|
|
|
# Commit only if there are actual changes.
|
|
git add -A
|
|
if git diff-index --quiet HEAD -- 2>/dev/null; then
|
|
echo "No changes to deploy."
|
|
else
|
|
git commit -m "Deploy ${GITHUB_SHA::7} from main"
|
|
fi
|
|
|
|
# Normal push (fast-forward compatible with Hostinger's git pull).
|
|
git push origin deploy
|
|
|
|
- name: Purge LiteSpeed Cache
|
|
if: success()
|
|
run: |
|
|
# Give Hostinger a moment to pull the new code.
|
|
sleep 10
|
|
|
|
# Trigger a cache purge via the WordPress REST API.
|
|
if [ -n "${{ secrets.WP_APP_PASSWORD }}" ]; then
|
|
curl -s -X POST \
|
|
-u "${{ secrets.WP_ADMIN_USER }}:${{ secrets.WP_APP_PASSWORD }}" \
|
|
"${{ secrets.WP_SITE_URL }}/wp-json/peptide-news/v1/cache-purge" \
|
|
--max-time 15 || echo "Cache purge skipped (endpoint not available)"
|
|
else
|
|
echo "No WP_APP_PASSWORD set — skipping remote cache purge."
|
|
fi
|
|
|
|
- name: Deploy summary
|
|
run: |
|
|
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Method:** Hostinger GIT auto-deploy (deploy branch)" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Deployed to:** ${{ secrets.WP_SITE_URL || 'peptiderepo.com' }}" >> $GITHUB_STEP_SUMMARY
|