-
Notifications
You must be signed in to change notification settings - Fork 1
33 lines (27 loc) · 1.1 KB
/
validate-student-pr.yml
File metadata and controls
33 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
name: validate student pr branches
on:
pull_request:
types: [opened, reopened, synchronize, edited, ready_for_review]
jobs:
validate-branch-rules:
runs-on: ubuntu-latest
steps:
- name: Validate PR base and head branch names
shell: bash
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
set -euo pipefail
if [[ "$BASE_REF" == "main" ]]; then
echo "::error::PRs to 'main' are not allowed. Open PRs to your personal handle branch."
exit 1
fi
escaped_base="$(printf '%s' "$BASE_REF" | sed -e 's/[][(){}.^$*+?|\\/]/\\&/g')"
expected_pattern="^${escaped_base}-.+$"
if [[ ! "$HEAD_REF" =~ $expected_pattern ]]; then
echo "::error::Invalid branch mapping. Expected '<base>-*' -> '<base>' (head must start with base name)."
echo "::error::Current mapping: '$HEAD_REF' -> '$BASE_REF'."
exit 1
fi
echo "Branch validation passed: '$HEAD_REF' -> '$BASE_REF'."