Skip to content

박은진 week2

박은진 week2 #100

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'."