Security (7 fixes): - SEC-001: Use wpdb->prepare() for COUNT query in REST API - SEC-002: Set httponly=true on session cookie to prevent XSS - SEC-003: Mask API keys in admin settings (show last 4 chars only) - SEC-004: Check capability before nonce in manual fetch handler - SEC-005: Validate redirect domains to prevent open redirects - SEC-006: Escape all article fields before REST API response - SEC-007: Add capability check to AJAX summary handler Infrastructure (7 fixes): - WPS-002: Clear cron schedule on plugin deactivation - WPS-003: Bundle Chart.js locally instead of CDN without SRI - WPS-004: Add uninstall.php for clean plugin removal - DB-001: Add foreign key constraints with CASCADE deletes - DB-002: Clamp pagination to valid page range - CI-001: Use StrictHostKeyChecking=accept-new in deploy - CI-002: Add security scanning step to CI pipeline - CI-003: Add rollback workflow via workflow_dispatch Performance & Quality (8 fixes): - PHP-001: Validate widget $instance as array before access - PHP-002: Return null from get_client_ip() for invalid IPs - PHP-003: Process RSS feeds in chunked batches of 10 - PHP-004: Wire up clear_article_cache() in fetch cycle - PERF-001: Cache source names in transient for strip_source_suffix - PERF-002: Add server-side transient caching for REST API - ARCH-002: Make LLM API URL configurable via WordPress options Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
129 lines
4.4 KiB
YAML
129 lines
4.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 --
|
|
sync-deploy-branch:
|
|
name: Sync 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).
|
|
git push origin deploy
|
|
|
|
# -- Deploy to Hostinger via rsync --
|
|
# Rsync the deploy branch content from the GH Actions runner directly
|
|
# to the plugin directory on Hostinger (avoids needing git access on server).
|
|
deploy:
|
|
name: Deploy to Hostinger
|
|
runs-on: ubuntu-latest
|
|
needs: sync-deploy-branch
|
|
environment: production
|
|
steps:
|
|
- name: Checkout deploy branch
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: deploy
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
if [ -n "${{ secrets.KNOWN_HOSTS }}" ]; then
|
|
echo "${{ secrets.KNOWN_HOSTS }}" >> ~/.ssh/known_hosts
|
|
else
|
|
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
fi
|
|
|
|
- name: Deploy via rsync
|
|
run: |
|
|
rsync -avz --delete \
|
|
--exclude='.git' \
|
|
--exclude='.github' \
|
|
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=accept-new" \
|
|
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-news-plugin/
|
|
|
|
- name: Purge LiteSpeed Cache
|
|
if: success()
|
|
run: |
|
|
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=accept-new \
|
|
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'ENDSSH'
|
|
CACHE_DIR="/home/${{ secrets.SSH_USERNAME }}/domains/peptiderepo.com/public_html/wp-content/litespeed"
|
|
if [ -d "$CACHE_DIR" ]; then
|
|
rm -rf "$CACHE_DIR"/*
|
|
echo "LiteSpeed cache purged."
|
|
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 SSH key
|
|
if: always()
|
|
run: rm -f ~/.ssh/deploy_key
|
|
|
|
- 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:** rsync from deploy branch to Hostinger" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Deployed to:** ${{ secrets.WP_SITE_URL || 'peptiderepo.com' }}" >> $GITHUB_STEP_SUMMARY
|