name: Auto-Promote Pipeline on: workflow_run: workflows: ["Deploy to Development"] types: - completed branches: [ develop ] permissions: actions: write contents: write jobs: test-and-promote-to-staging: name: Test Dev and Auto-Promote to Staging runs-on: ubuntu-latest environment: development 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..." # Use the canonical Knative domain CANONICAL_URL="https://game-2048-dev.game-2048-dev.${{ secrets.DEV_DOMAIN }}" echo "Testing canonical domain: $CANONICAL_URL" canonical_response=$(curl -s -o /dev/null -w "%{http_code}" -L --max-time 30 "$CANONICAL_URL") if [ "$canonical_response" != "200" ]; then echo "โŒ Canonical domain returned HTTP $canonical_response" exit 1 fi echo "โœ… Canonical domain accessible" # Test content validation on canonical domain echo "Testing content validation on canonical domain..." content=$(curl -s -L --max-time 30 "$CANONICAL_URL") 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 "$CANONICAL_URL") 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 "- Canonical 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