File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : CMS Branch Guard
2+
3+ on :
4+ pull_request :
5+
6+ jobs :
7+ restrict-cms-branches :
8+ runs-on : ubuntu-latest
9+
10+ steps :
11+ - name : Checkout repo
12+ uses : actions/checkout@v4
13+ with :
14+ fetch-depth : 0 # IMPORTANT for diff to work properly
15+
16+ - name : Validate CMS branch changes
17+ run : |
18+ BRANCH_NAME="${{ github.head_ref }}"
19+ BASE_REF="${{ github.base_ref }}"
20+
21+ echo "Branch: $BRANCH_NAME"
22+ echo "Base: $BASE_REF"
23+
24+ if [[ "$BRANCH_NAME" == cms/* ]]; then
25+ echo "CMS branch detected — enforcing content rules"
26+
27+ # Get changed files (including renames, deletions, etc.)
28+ CHANGED_FILES=$(git diff --name-only origin/$BASE_REF...HEAD)
29+
30+ echo "Changed files:"
31+ echo "$CHANGED_FILES"
32+
33+ # Allowed patterns:
34+ # 1. Content files
35+ # 2. Upload images
36+ ALLOWED_REGEX="^(projects/website-angular/content/.*\.(md|json|yml)|projects/website-angular/public/uploads/.*\.(png|jpg|jpeg|webp|gif|svg))$"
37+
38+ # Find invalid files
39+ INVALID_FILES=$(echo "$CHANGED_FILES" | grep -vE "$ALLOWED_REGEX" || true)
40+
41+ if [ -n "$INVALID_FILES" ]; then
42+ echo ""
43+ echo "ERROR: Invalid files detected in CMS branch"
44+ echo ""
45+ echo "The following files are NOT allowed:"
46+ echo "$INVALID_FILES"
47+ echo ""
48+ echo "The following files are allowed:"
49+ echo " - projects/website-angular/content/**/*.md|json|yml"
50+ echo " - projects/website-angular/public/uploads/**/*.(png|jpg|jpeg|webp|gif|svg)"
51+ echo ""
52+ echo "Tip: CMS branches (cms/*) are only for content editing."
53+ echo " If you need to change code, create a separate branch."
54+ echo ""
55+
56+ exit 1
57+ else
58+ echo ""
59+ echo "All changes are valid for a CMS branch!"
60+ echo ""
61+ fi
62+
63+ else
64+ echo "Not a CMS branch — skipping CMS restrictions"
65+ fi
You can’t perform that action at this time.
0 commit comments