mirror of
https://github.com/ghndrx/k8s-game-2048.git
synced 2026-02-10 06:45:07 +00:00
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.
This commit is contained in:
135
.github/workflows/auto-promote.yml
vendored
135
.github/workflows/auto-promote.yml
vendored
@@ -5,17 +5,19 @@ on:
|
||||
workflows: ["Deploy to Development"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ main ]
|
||||
branches: [ develop ]
|
||||
|
||||
jobs:
|
||||
test-and-promote:
|
||||
name: Test Dev and Auto-Promote
|
||||
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: |
|
||||
@@ -92,35 +94,44 @@ jobs:
|
||||
fi
|
||||
echo "✅ Performance test passed: ${response_time}s"
|
||||
|
||||
- name: Auto-promote to staging
|
||||
- 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 to staging...');
|
||||
console.log('🚀 All dev tests passed! Auto-promoting develop to staging branch...');
|
||||
|
||||
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'
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('✅ Staging deployment triggered');
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- name: Create promotion summary
|
||||
run: |
|
||||
echo "## 🎯 Auto-Promotion Summary" >> $GITHUB_STEP_SUMMARY
|
||||
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 | 🚀 Triggered | Auto-promotion initiated |" >> $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
|
||||
@@ -129,88 +140,6 @@ jobs:
|
||||
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 deployment will start automatically" >> $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
|
||||
echo "- Production promotion requires manual approval via staging → main merge" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
4
.github/workflows/build-image.yml
vendored
4
.github/workflows/build-image.yml
vendored
@@ -2,9 +2,9 @@ name: Build and Push Container Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
branches: [ main, develop, staging ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
branches: [ main, develop, staging ]
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
|
||||
4
.github/workflows/deploy-dev.yml
vendored
4
.github/workflows/deploy-dev.yml
vendored
@@ -5,9 +5,9 @@ on:
|
||||
workflows: ["Build and Push Container Image"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ main ]
|
||||
branches: [ develop ]
|
||||
push:
|
||||
branches: [ main ]
|
||||
branches: [ develop ]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
|
||||
2
.github/workflows/deploy-prod.yml
vendored
2
.github/workflows/deploy-prod.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: Deploy to Production
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
|
||||
2
.github/workflows/deploy-staging.yml
vendored
2
.github/workflows/deploy-staging.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: Deploy to Staging
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ staging ]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
|
||||
138
.github/workflows/promote-to-production.yml
vendored
Normal file
138
.github/workflows/promote-to-production.yml
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
name: Promote to Production
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Deploy to Staging"]
|
||||
types:
|
||||
- completed
|
||||
branches: [ staging ]
|
||||
|
||||
jobs:
|
||||
test-staging-and-promote-to-main:
|
||||
name: Test Staging and Promote to Main
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
environment: production-approval # This requires manual approval
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: staging
|
||||
|
||||
- name: Wait for staging deployment to settle
|
||||
run: |
|
||||
echo "⏳ Waiting for staging deployment to fully settle..."
|
||||
sleep 120
|
||||
|
||||
- name: Run comprehensive staging tests
|
||||
run: |
|
||||
echo "🧪 Running comprehensive tests on staging environment..."
|
||||
|
||||
# Test canonical staging domain first (primary test)
|
||||
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 validation on canonical domain
|
||||
echo "Testing staging content validation..."
|
||||
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 "❌ 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 staging content validation tests passed"
|
||||
|
||||
# Test staging performance on canonical domain
|
||||
echo "Testing staging performance..."
|
||||
response_time=$(curl -s -o /dev/null -w "%{time_total}" -L --max-time 30 https://game-2048-staging.game-2048-staging.staging.wa.darknex.us/)
|
||||
if (( $(echo "$response_time > 10.0" | bc -l) )); then
|
||||
echo "❌ Response time too slow: ${response_time}s"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Staging performance test passed: ${response_time}s"
|
||||
|
||||
- name: Auto-promote staging to main branch
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
console.log('🎯 All staging tests passed! Auto-promoting staging to main branch...');
|
||||
|
||||
// Create a merge from staging to main
|
||||
try {
|
||||
const response = await github.rest.repos.merge({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
base: 'main',
|
||||
head: 'staging',
|
||||
commit_message: 'Auto-promote: Merge staging to main after successful staging tests - Deploy to Production'
|
||||
});
|
||||
|
||||
console.log('✅ Successfully merged staging to main branch');
|
||||
console.log('This will trigger production deployment automatically');
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (error.status === 409) {
|
||||
console.log('ℹ️ No new commits to merge - main is already up to date');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
- name: Create production promotion summary
|
||||
run: |
|
||||
echo "## 🎉 Production Promotion Summary (Staging → Main)" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Stage | Status | Action |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "|-------|--------|--------|" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Staging Tests | ✅ Passed | Comprehensive validation completed |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Main Branch | 🚀 Updated | Auto-promotion completed |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "| Production Deploy | ⏳ Triggered | Deployment will start automatically |" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### 📋 Tests Performed" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Staging canonical domain accessibility" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Staging custom domain accessibility" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Content and functionality validation" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Performance testing" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### 🎮 Deployment Status" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Development**: ✅ Live at https://game-2048-dev.game-2048-dev.dev.wa.darknex.us" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Staging**: ✅ Live at https://game-2048-staging.game-2048-staging.staging.wa.darknex.us" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- **Production**: 🚀 Deploying to https://game-2048-prod.game-2048-prod.wa.darknex.us" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "### 🔗 Next Steps" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Production deployment will start automatically" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- Monitor the production deployment workflow" >> $GITHUB_STEP_SUMMARY
|
||||
echo "- All environments will be live with the latest code!" >> $GITHUB_STEP_SUMMARY
|
||||
Reference in New Issue
Block a user