133 lines
4.8 KiB
YAML
Executable File
133 lines
4.8 KiB
YAML
Executable File
name: Deploy to WordPress
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
concurrency:
|
|
group: deploy-production
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
test:
|
|
name: Pre-deploy tests
|
|
uses: ./.github/workflows/ci.yml
|
|
|
|
deploy-staging:
|
|
name: Deploy to Staging
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
environment: staging
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: main
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
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 || true
|
|
- name: Deploy via rsync → staging
|
|
run: |
|
|
rsync -avz --delete \
|
|
--exclude='.git' --exclude='.github' \
|
|
--exclude='tests' --exclude='phpunit.xml.dist' \
|
|
--exclude='ARCHITECTURE.md' --exclude='CONVENTIONS.md' --exclude='CHANGELOG.md' \
|
|
-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/staging/wp-content/plugins/peptide-news-plugin/
|
|
- name: Staging health check
|
|
run: |
|
|
sleep 5
|
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://staging.peptiderepo.com/ || echo "000")
|
|
echo "Staging responded: HTTP $STATUS"
|
|
- name: Cleanup
|
|
if: always()
|
|
run: rm -f ~/.ssh/deploy_key
|
|
|
|
sync-deploy-branch:
|
|
name: Sync deploy branch
|
|
runs-on: ubuntu-latest
|
|
needs: [test, deploy-staging]
|
|
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"
|
|
git fetch origin deploy:deploy 2>/dev/null || true
|
|
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
|
|
git rm -rf . > /dev/null 2>&1 || true
|
|
git checkout main -- \
|
|
admin/ \
|
|
includes/ \
|
|
languages/ \
|
|
public/ \
|
|
peptide-news-plugin.php
|
|
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
|
|
git push origin deploy
|
|
|
|
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
|
|
ENDSSH
|
|
- name: Cleanup SSH key
|
|
if: always()
|
|
run: rm -f ~/.ssh/deploy_key
|
|
- name: Deploy summary
|
|
run: |
|
|
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Commit:** \`${GITHUB_SHA::7}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Deployed to:** peptiderepo.com" >> $GITHUB_STEP_SUMMARY
|