|
1 | 1 | # ───────────────────────────────────────────────────────────────── |
2 | | -# Dev to Main Workflow (Release Gates) |
| 2 | +# Release to Main Workflow (Release Gates) |
3 | 3 | # ───────────────────────────────────────────────────────────────── |
4 | 4 | # Validates release pull requests before merging to main (production). |
5 | 5 | # |
6 | 6 | # Release Gates: |
7 | | -# - Source must be 'dev' branch only |
| 7 | +# - Source must be dev, test/*, or release/* branches |
8 | 8 | # - Production build must succeed |
9 | 9 | # - Smoke tests must pass |
10 | 10 | # - Security quick scan (informational only) |
11 | 11 | # - Deployment readiness checklist |
12 | 12 | # |
| 13 | +# Allowed source branches: |
| 14 | +# - dev: Production releases |
| 15 | +# - test/*: Workflow validation and testing |
| 16 | +# - release/*: Hotfix releases |
| 17 | +# - dependabot/*: Automated dependency updates |
| 18 | +# |
13 | 19 | # Author: Alireza Rezvani |
14 | 20 | # Date: 2025-11-06 |
15 | 21 | # ───────────────────────────────────────────────────────────────── |
@@ -60,19 +66,27 @@ jobs: |
60 | 66 | exit 0 |
61 | 67 | fi |
62 | 68 |
|
63 | | - if [[ "$SOURCE_BRANCH" != "dev" ]]; then |
| 69 | + # Allowlist: branches permitted to merge to main |
| 70 | + # Includes: dev (production), test/* (validation), release/* (hotfixes) |
| 71 | + ALLOWED_REGEX='^(dev|test/.*|release/.*)$' |
| 72 | +
|
| 73 | + if [[ ! $SOURCE_BRANCH =~ $ALLOWED_REGEX ]]; then |
64 | 74 | echo "❌ Invalid source branch: $SOURCE_BRANCH" |
65 | 75 | echo "" |
66 | | - echo "Only 'dev' branch can be merged to 'main' for releases." |
| 76 | + echo "Only branches matching the allowlist may be merged to 'main'." |
| 77 | + echo "" |
| 78 | + echo "Allowed patterns:" |
| 79 | + echo " - dev (production releases)" |
| 80 | + echo " - test/* (workflow validation)" |
| 81 | + echo " - release/* (hotfix releases)" |
67 | 82 | echo "" |
68 | | - echo "Expected: dev → main" |
69 | 83 | echo "Got: $SOURCE_BRANCH → main" |
70 | 84 | echo "" |
71 | | - echo "If using a different branching strategy, adjust this workflow." |
| 85 | + echo "If using a different branching strategy, adjust ALLOWED_REGEX in this workflow." |
72 | 86 | exit 1 |
73 | 87 | fi |
74 | 88 |
|
75 | | - echo "✅ Source branch is valid: dev → main" |
| 89 | + echo "✅ Source branch is valid: $SOURCE_BRANCH → main" |
76 | 90 |
|
77 | 91 | # ───────────────────────────────────────────────────────────────── |
78 | 92 | # Production Build Validation |
@@ -397,14 +411,26 @@ jobs: |
397 | 411 |
|
398 | 412 | echo "" >> $GITHUB_STEP_SUMMARY |
399 | 413 |
|
400 | | - # Overall status |
401 | | - if [[ "${{ needs.validate-source.result }}" == "failure" ]] || \ |
402 | | - [[ "${{ needs.build-prod.result }}" == "failure" ]] || \ |
403 | | - [[ "${{ needs.smoke-tests.result }}" == "failure" ]] || \ |
404 | | - [[ "${{ needs.deployment-readiness.result }}" == "failure" ]]; then |
| 414 | + # Overall status - check if ALL gates passed |
| 415 | + # Treat anything other than "success" as blocking (including "skipped", "failure", "cancelled") |
| 416 | + VALIDATE_RESULT="${{ needs.validate-source.result }}" |
| 417 | + BUILD_RESULT="${{ needs.build-prod.result }}" |
| 418 | + SMOKE_RESULT="${{ needs.smoke-tests.result }}" |
| 419 | + DEPLOY_RESULT="${{ needs.deployment-readiness.result }}" |
| 420 | +
|
| 421 | + if [[ "$VALIDATE_RESULT" != "success" ]] || \ |
| 422 | + [[ "$BUILD_RESULT" != "success" ]] || \ |
| 423 | + [[ "$SMOKE_RESULT" != "success" ]] || \ |
| 424 | + [[ "$DEPLOY_RESULT" != "success" ]]; then |
405 | 425 | echo "## ❌ Release Blocked" >> $GITHUB_STEP_SUMMARY |
406 | 426 | echo "" >> $GITHUB_STEP_SUMMARY |
407 | | - echo "One or more release gates failed. Please fix the issues before merging to production." >> $GITHUB_STEP_SUMMARY |
| 427 | + echo "One or more release gates did not pass. Please fix the issues before merging to production." >> $GITHUB_STEP_SUMMARY |
| 428 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 429 | + echo "**Gate Results:**" >> $GITHUB_STEP_SUMMARY |
| 430 | + echo "- Source validation: $VALIDATE_RESULT" >> $GITHUB_STEP_SUMMARY |
| 431 | + echo "- Production build: $BUILD_RESULT" >> $GITHUB_STEP_SUMMARY |
| 432 | + echo "- Smoke tests: $SMOKE_RESULT" >> $GITHUB_STEP_SUMMARY |
| 433 | + echo "- Deployment readiness: $DEPLOY_RESULT" >> $GITHUB_STEP_SUMMARY |
408 | 434 | exit 1 |
409 | 435 | else |
410 | 436 | echo "## ✅ Release Approved" >> $GITHUB_STEP_SUMMARY |
|
0 commit comments