Replace broken SCP/SSH deploy (blocked by Hostinger firewall) with a deploy-branch strategy. After CI passes, GitHub Actions pushes only plugin files to the 'deploy' branch. Hostinger's built-in GIT integration watches this branch via webhook and auto-pulls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
83 lines
2.9 KiB
YAML
83 lines
2.9 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: Build deploy branch
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
# Create a temporary orphan branch with only plugin files.
|
|
git checkout --orphan deploy-staging
|
|
|
|
# Remove everything from the index.
|
|
git rm -rf --cached . > /dev/null 2>&1 || true
|
|
|
|
# Stage only the plugin runtime files.
|
|
git add -f \
|
|
admin/ \
|
|
includes/ \
|
|
languages/ \
|
|
public/ \
|
|
peptide-news-plugin.php
|
|
|
|
git commit -m "Deploy ${GITHUB_SHA::7} from main"
|
|
|
|
# Force-push to the deploy branch (Hostinger webhook triggers auto-pull).
|
|
git push --force origin deploy-staging: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
|