Skip to content

Commit 523ea47

Browse files
authored
docs: Add GitHub Actions workflow to block preview branch merges (#36276)
This PR adds a GitHub Actions workflow that prevents merges from preview branches (release-preview-* pattern) to any target branches. The workflow provides automated protection against accidental merges that could cause version conflicts or unintended promotion of preview content. Key features: - Monitors all pull requests for release-preview-* source branches - Blocks merges to any target branch with clear error messages - Provides step-by-step resolution guidance - Includes comprehensive job summaries and support contact info - Uses PowerShell script for reliable pattern matching Linked to ADO work item: AB#545482
1 parent f0717e7 commit 523ea47

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Block preview branch merges
2+
3+
permissions:
4+
pull-requests: write
5+
statuses: write
6+
checks: write
7+
8+
on:
9+
pull_request:
10+
types: [opened, synchronize, reopened]
11+
# Monitor all target branches since preview branches cannot merge to ANY branch
12+
13+
jobs:
14+
block-preview:
15+
name: Block preview branch merge
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Check head reference restrictions
20+
shell: pwsh
21+
env:
22+
HEAD_REF: ${{ github.head_ref }}
23+
BASE_REF: ${{ github.base_ref }}
24+
PR_NUMBER: ${{ github.event.number }}
25+
REPO_NAME: ${{ github.repository }}
26+
run: |
27+
Write-Host "Checking merge restrictions for PR #$env:PR_NUMBER"
28+
Write-Host "Head reference: $env:HEAD_REF"
29+
Write-Host "Base reference: $env:BASE_REF"
30+
Write-Host "Repository: $env:REPO_NAME"
31+
32+
if ($env:HEAD_REF -like "release-preview-*") {
33+
Write-Host "❌ MERGE BLOCKED: Preview branch detected"
34+
Write-Host ""
35+
Write-Host "This pull request is attempting to merge from a preview branch"
36+
Write-Host "to '$env:BASE_REF', which is not permitted."
37+
Write-Host ""
38+
Write-Host "IMPORTANT: Preview content cannot be merged into other branches directly"
39+
Write-Host "from branches named 'release-preview-*'."
40+
Write-Host ""
41+
Write-Host "To merge such branches:"
42+
Write-Host "1. Create a new branch from your target branch"
43+
Write-Host "2. Squash the changes to one commit"
44+
Write-Host "3. Create a new pull request from the new branch"
45+
Write-Host ""
46+
Write-Host "This restriction maintains content quality and prevents preview"
47+
Write-Host "material from inadvertently entering production branches."
48+
49+
# Set job summary for GitHub UI
50+
echo "# 🚫 Merge Blocked - Preview Branch" >> $env:GITHUB_STEP_SUMMARY
51+
echo "" >> $env:GITHUB_STEP_SUMMARY
52+
echo "This pull request cannot be merged because it originates from a **preview branch**." >> $env:GITHUB_STEP_SUMMARY
53+
echo "" >> $env:GITHUB_STEP_SUMMARY
54+
echo "## Restriction Details" >> $env:GITHUB_STEP_SUMMARY
55+
echo "- **Head branch:** $env:HEAD_REF" >> $env:GITHUB_STEP_SUMMARY
56+
echo "- **Target branch:** $env:BASE_REF" >> $env:GITHUB_STEP_SUMMARY
57+
echo "- **Restriction:** Preview content cannot be merged directly from 'release-preview-*' branches" >> $env:GITHUB_STEP_SUMMARY
58+
echo "" >> $env:GITHUB_STEP_SUMMARY
59+
echo "## Why This Restriction Exists" >> $env:GITHUB_STEP_SUMMARY
60+
echo "This restriction maintains content quality and prevents preview material from inadvertently entering production branches." >> $env:GITHUB_STEP_SUMMARY
61+
echo "" >> $env:GITHUB_STEP_SUMMARY
62+
echo "## Resolution Steps" >> $env:GITHUB_STEP_SUMMARY
63+
echo "1. Create a new branch from **$env:BASE_REF**" >> $env:GITHUB_STEP_SUMMARY
64+
echo "2. Squash the changes to one commit" >> $env:GITHUB_STEP_SUMMARY
65+
echo "3. Create a new pull request from the new branch" >> $env:GITHUB_STEP_SUMMARY
66+
echo "" >> $env:GITHUB_STEP_SUMMARY
67+
echo "## Need Help?" >> $env:GITHUB_STEP_SUMMARY
68+
echo "Contact the [SQL Docs team](mailto:dbdocsprreviews@microsoft.com) for assistance with this restriction." >> $env:GITHUB_STEP_SUMMARY
69+
70+
exit 1
71+
} else {
72+
Write-Host "✅ Merge allowed: Head reference '$env:HEAD_REF' is permitted"
73+
echo "# ✅ Merge Check Passed" >> $env:GITHUB_STEP_SUMMARY
74+
echo "Head branch **$env:HEAD_REF** is allowed to merge to **$env:BASE_REF**." >> $env:GITHUB_STEP_SUMMARY
75+
}

0 commit comments

Comments
 (0)