Files
k8s-game-2048/.github/workflows/auto-promote.yml
Greg 09ec016b6a feat: Implement proper branch-based auto-promotion strategy
🚀 **New Branching Strategy:**
- develop → triggers dev deployment → auto-promotes to staging branch
- staging → triggers staging deployment → manual approval → promotes to main branch
- main → triggers production deployment

📝 **Workflow Changes:**
- deploy-dev.yml: Now triggers on develop branch
- deploy-staging.yml: Now triggers on staging branch push
- deploy-prod.yml: Now triggers on main branch push
- auto-promote.yml: Tests dev → merges develop to staging branch
- promote-to-production.yml: Tests staging → requires approval → merges staging to main
- build-image.yml: Now builds on all branches (main, develop, staging)

🎯 **Auto-Promotion Flow:**
1. Push to develop → Deploy to dev → Test → Auto-merge to staging
2. Staging deployment → Test → Manual approval → Auto-merge to main
3. Main deployment → Production live!

This provides proper separation between environments with appropriate gates.
2025-06-30 23:18:14 -07:00

146 lines
5.9 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Auto-Promote Pipeline
on:
workflow_run:
workflows: ["Deploy to Development"]
types:
- completed
branches: [ develop ]
jobs:
test-and-promote-to-staging:
name: Test Dev and Auto-Promote to Staging
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: develop
- name: Wait for dev deployment to settle
run: |
echo "⏳ Waiting for dev deployment to fully settle..."
sleep 60
- name: Run comprehensive dev tests
run: |
echo "🧪 Running comprehensive tests on dev environment..."
# Test canonical domain first (primary test)
echo "Testing canonical domain: game-2048-dev.game-2048-dev.dev.wa.darknex.us"
canonical_response=$(curl -s -o /dev/null -w "%{http_code}" -L --max-time 30 https://game-2048-dev.game-2048-dev.dev.wa.darknex.us/)
if [ "$canonical_response" != "200" ]; then
echo "❌ Canonical domain returned HTTP $canonical_response"
exit 1
fi
echo "✅ Canonical domain accessible"
# Test SSL certificate on custom domain
echo "Testing SSL certificate on custom domain..."
cert_expiry=$(echo | openssl s_client -servername 2048-dev.wa.darknex.us -connect 2048-dev.wa.darknex.us:443 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2)
expiry_epoch=$(date -d "$cert_expiry" +%s)
current_epoch=$(date +%s)
days_until_expiry=$(( (expiry_epoch - current_epoch) / 86400 ))
if [ $days_until_expiry -lt 30 ]; then
echo "❌ SSL certificate expires in less than 30 days!"
exit 1
fi
echo "✅ SSL certificate valid for $days_until_expiry days"
# Test custom domain accessibility
echo "Testing custom domain accessibility..."
response_code=$(curl -s -o /dev/null -w "%{http_code}" -L --max-time 30 https://2048-dev.wa.darknex.us/)
if [ "$response_code" != "200" ]; then
echo "❌ Custom domain returned HTTP $response_code"
exit 1
fi
echo "✅ Custom domain accessible"
# Test content validation on canonical domain
echo "Testing content validation on canonical domain..."
content=$(curl -s -L --max-time 30 https://game-2048-dev.game-2048-dev.dev.wa.darknex.us/)
if ! echo "$content" | grep -q "2048"; then
echo "❌ Content missing 2048 title"
exit 1
fi
if ! echo "$content" | grep -q "HOW TO PLAY"; then
echo "❌ Content missing game instructions"
exit 1
fi
if ! echo "$content" | grep -q "style.css"; then
echo "❌ CSS file not referenced"
exit 1
fi
if ! echo "$content" | grep -q "script.js"; then
echo "❌ JavaScript file not referenced"
exit 1
fi
echo "✅ All content validation tests passed"
# Test performance on canonical domain
echo "Testing performance on canonical domain..."
response_time=$(curl -s -o /dev/null -w "%{time_total}" -L --max-time 30 https://game-2048-dev.game-2048-dev.dev.wa.darknex.us/)
if (( $(echo "$response_time > 10.0" | bc -l) )); then
echo "❌ Response time too slow: ${response_time}s"
exit 1
fi
echo "✅ Performance test passed: ${response_time}s"
- name: Auto-promote develop to staging branch
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log('🚀 All dev tests passed! Auto-promoting develop to staging branch...');
// Create a merge from develop to staging
try {
const response = await github.rest.repos.merge({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'staging',
head: 'develop',
commit_message: 'Auto-promote: Merge develop to staging after successful dev tests'
});
console.log('✅ Successfully merged develop to staging branch');
console.log('This will trigger staging deployment automatically');
return response;
} catch (error) {
if (error.status === 409) {
console.log(' No new commits to merge - staging is already up to date');
} else {
throw error;
}
}
- name: Create promotion summary
run: |
echo "## 🎯 Auto-Promotion Summary (Develop → Staging)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status | Action |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Dev Tests | ✅ Passed | Comprehensive validation completed |" >> $GITHUB_STEP_SUMMARY
echo "| Staging Branch | 🚀 Updated | Auto-promotion completed |" >> $GITHUB_STEP_SUMMARY
echo "| Staging Deploy | ⏳ Triggered | Deployment will start automatically |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📋 Tests Performed" >> $GITHUB_STEP_SUMMARY
echo "- SSL certificate validation" >> $GITHUB_STEP_SUMMARY
echo "- Domain accessibility check" >> $GITHUB_STEP_SUMMARY
echo "- Content and functionality validation" >> $GITHUB_STEP_SUMMARY
echo "- Performance testing" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔗 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "- Staging deployment will start automatically" >> $GITHUB_STEP_SUMMARY
echo "- Staging tests will run automatically" >> $GITHUB_STEP_SUMMARY
echo "- Production promotion requires manual approval via staging → main merge" >> $GITHUB_STEP_SUMMARY