mirror of
https://github.com/ghndrx/k8s-game-2048.git
synced 2026-02-10 06:45:07 +00:00
✨ Improvements: - Prioritize canonical domain testing over custom domains - Add fallback testing for both canonical and custom domains - More reliable smoke tests using direct Knative service URLs - Separate performance testing for canonical vs custom domains - Enhanced auto-promotion pipeline with canonical domain validation 🧪 Testing Strategy: - Primary: Test canonical domains (game-2048-*.*.wa.darknex.us) - Secondary: Verify custom domains work via redirects - Fallback: Test both domains in smoke tests for reliability 🔗 Canonical Domains: - Dev: game-2048-dev.game-2048-dev.dev.wa.darknex.us - Staging: game-2048-staging.game-2048-staging.staging.wa.darknex.us - Prod: game-2048-prod.game-2048-prod.wa.darknex.us This ensures tests are more reliable since canonical domains are always accessible while custom domains may have redirect complexity.
217 lines
8.7 KiB
YAML
217 lines
8.7 KiB
YAML
name: Auto-Promote Pipeline
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Deploy to Development"]
|
|
types:
|
|
- completed
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
test-and-promote:
|
|
name: Test Dev and Auto-Promote
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- 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 to staging
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
console.log('🚀 All dev tests passed! Auto-promoting to staging...');
|
|
|
|
const response = await github.rest.actions.createWorkflowDispatch({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
workflow_id: 'deploy-staging.yml',
|
|
ref: 'main',
|
|
inputs: {
|
|
image_tag: 'latest'
|
|
}
|
|
});
|
|
|
|
console.log('✅ Staging deployment triggered');
|
|
|
|
return response;
|
|
|
|
- name: Create promotion summary
|
|
run: |
|
|
echo "## 🎯 Auto-Promotion Summary" >> $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 | 🚀 Triggered | Auto-promotion initiated |" >> $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 "- Monitor staging deployment progress" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Staging tests will run automatically" >> $GITHUB_STEP_SUMMARY
|
|
echo "- Production promotion requires manual approval" >> $GITHUB_STEP_SUMMARY
|
|
|
|
promote-to-production:
|
|
name: Test Staging and Promote to Production
|
|
runs-on: ubuntu-latest
|
|
needs: test-and-promote
|
|
if: success()
|
|
environment: production-approval # This requires manual approval
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Wait for staging deployment
|
|
run: |
|
|
echo "⏳ Waiting for staging deployment to complete..."
|
|
sleep 120 # Give staging time to deploy
|
|
|
|
- name: Test staging environment
|
|
run: |
|
|
echo "🧪 Running staging tests..."
|
|
|
|
# Test canonical staging domain first
|
|
echo "Testing canonical staging domain: game-2048-staging.game-2048-staging.staging.wa.darknex.us"
|
|
canonical_response=$(curl -s -o /dev/null -w "%{http_code}" -L --max-time 30 https://game-2048-staging.game-2048-staging.staging.wa.darknex.us/)
|
|
if [ "$canonical_response" != "200" ]; then
|
|
echo "❌ Staging canonical domain returned HTTP $canonical_response"
|
|
exit 1
|
|
fi
|
|
echo "✅ Staging canonical domain accessible"
|
|
|
|
# Test custom staging domain
|
|
echo "Testing custom staging domain: 2048-staging.wa.darknex.us"
|
|
response_code=$(curl -s -o /dev/null -w "%{http_code}" -L --max-time 30 https://2048-staging.wa.darknex.us/)
|
|
if [ "$response_code" != "200" ]; then
|
|
echo "❌ Staging custom domain returned HTTP $response_code"
|
|
exit 1
|
|
fi
|
|
echo "✅ Staging custom domain accessible"
|
|
|
|
# Test staging content on canonical domain
|
|
echo "Testing staging content..."
|
|
content=$(curl -s -L --max-time 30 https://game-2048-staging.game-2048-staging.staging.wa.darknex.us/)
|
|
if ! echo "$content" | grep -q "2048"; then
|
|
echo "❌ Staging content validation failed"
|
|
exit 1
|
|
fi
|
|
echo "✅ Staging content validation passed"
|
|
|
|
- name: Auto-promote to production
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
console.log('🎯 Staging tests passed! Promoting to production...');
|
|
|
|
const response = await github.rest.actions.createWorkflowDispatch({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
workflow_id: 'deploy-prod.yml',
|
|
ref: 'main',
|
|
inputs: {
|
|
image_tag: 'latest',
|
|
confirmation: 'DEPLOY'
|
|
}
|
|
});
|
|
|
|
console.log('🚀 Production deployment triggered');
|
|
|
|
return response;
|
|
|
|
- name: Create final summary
|
|
run: |
|
|
echo "## 🎉 Full Pipeline Completion" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Environment | Status | URL |" >> $GITHUB_STEP_SUMMARY
|
|
echo "|-------------|--------|-----|" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Development | ✅ Tested & Live | https://2048-dev.wa.darknex.us |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Staging | ✅ Tested & Live | https://2048-staging.wa.darknex.us |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Production | 🚀 Deploying | https://2048.wa.darknex.us |" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 🎮 Your 2048 Game is Live!" >> $GITHUB_STEP_SUMMARY
|
|
echo "All environments have been automatically tested and promoted successfully." >> $GITHUB_STEP_SUMMARY
|