ci: split deploy.yml into staging→production pipeline with approval gate
This commit is contained in:
86
.github/workflows/deploy.yml
vendored
86
.github/workflows/deploy.yml
vendored
@@ -4,21 +4,20 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: deploy-prautoblogger-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
validate:
|
validate:
|
||||||
name: PHP Lint Gate
|
name: PHP Lint Gate
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
- uses: shivammathur/setup-php@v2
|
||||||
|
|
||||||
- name: Setup PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
with:
|
||||||
php-version: '8.1'
|
php-version: '8.1'
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: PHP Lint Check
|
- name: PHP Lint Check
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
@@ -29,38 +28,62 @@ jobs:
|
|||||||
-not -path './.github/*' \
|
-not -path './.github/*' \
|
||||||
-print0 | xargs -0 -n1 -P4 php -l > /dev/null
|
-print0 | xargs -0 -n1 -P4 php -l > /dev/null
|
||||||
|
|
||||||
deploy:
|
deploy-staging:
|
||||||
|
name: Deploy to Staging
|
||||||
needs: validate
|
needs: validate
|
||||||
name: Deploy to Production
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment: staging
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup SSH key
|
- name: Setup SSH key
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||||
chmod 600 ~/.ssh/deploy_key
|
chmod 600 ~/.ssh/deploy_key
|
||||||
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
- name: Deploy via rsync → staging
|
||||||
- name: Deploy via rsync
|
|
||||||
run: |
|
run: |
|
||||||
rsync -avz --delete \
|
rsync -avz --delete \
|
||||||
--exclude '.git' \
|
--exclude '.git' --exclude '.github' \
|
||||||
--exclude '.github' \
|
--exclude 'tests' --exclude 'phpunit.xml.dist' \
|
||||||
--exclude 'tests' \
|
--exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
--exclude 'phpunit.xml.dist' \
|
--exclude 'vendor' --exclude '.distignore' \
|
||||||
--exclude 'composer.json' \
|
--exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' \
|
||||||
--exclude 'composer.lock' \
|
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
||||||
--exclude 'vendor' \
|
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/staging/wp-content/plugins/prautoblogger/
|
||||||
--exclude '.distignore' \
|
- name: Staging health check
|
||||||
--exclude 'ARCHITECTURE.md' \
|
run: |
|
||||||
--exclude 'CONVENTIONS.md' \
|
sleep 5
|
||||||
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://staging.peptiderepo.com/ || echo "000")
|
||||||
|
echo "Staging responded: HTTP $STATUS"
|
||||||
|
[ "$STATUS" = "000" ] && echo "Warning: staging DNS may still be propagating" || true
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
|
||||||
|
deploy-production:
|
||||||
|
name: Deploy to Production
|
||||||
|
needs: [validate, deploy-staging]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- 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
|
||||||
|
- name: Deploy via rsync → production
|
||||||
|
run: |
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude '.git' --exclude '.github' \
|
||||||
|
--exclude 'tests' --exclude 'phpunit.xml.dist' \
|
||||||
|
--exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
|
--exclude 'vendor' --exclude '.distignore' \
|
||||||
|
--exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' \
|
||||||
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
||||||
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/wp-content/plugins/prautoblogger/
|
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/wp-content/plugins/prautoblogger/
|
||||||
|
|
||||||
- name: Purge LiteSpeed Cache
|
- name: Purge LiteSpeed Cache
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} \
|
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} \
|
||||||
@@ -68,22 +91,15 @@ jobs:
|
|||||||
"cd ~/domains/peptiderepo.com/public_html && \
|
"cd ~/domains/peptiderepo.com/public_html && \
|
||||||
wp litespeed-purge all 2>/dev/null || \
|
wp litespeed-purge all 2>/dev/null || \
|
||||||
(find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null) || true"
|
(find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null) || true"
|
||||||
|
- name: Production health check
|
||||||
- name: Health check
|
|
||||||
run: |
|
run: |
|
||||||
sleep 5
|
sleep 5
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://peptiderepo.com)
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://peptiderepo.com)
|
||||||
# 200 = normal healthy response.
|
|
||||||
# 403 = peptide-starter-theme v1.5.2 CF-peer validator rejecting this
|
|
||||||
# GHA-runner direct-to-origin request as non-Cloudflare traffic.
|
|
||||||
# That rejection is the validator working — itself a positive
|
|
||||||
# liveness signal. Real user traffic via Cloudflare gets 200.
|
|
||||||
if [ "$STATUS" != "200" ] && [ "$STATUS" != "403" ]; then
|
if [ "$STATUS" != "200" ] && [ "$STATUS" != "403" ]; then
|
||||||
echo "ERROR: Site returned unexpected HTTP $STATUS after deploy"
|
echo "ERROR: Site returned unexpected HTTP $STATUS after deploy"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Site is responsive (HTTP $STATUS)"
|
echo "Production healthy (HTTP $STATUS)"
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: rm -f ~/.ssh/deploy_key
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
|||||||
Reference in New Issue
Block a user