From a0a86b054fd3304f8c4b8aed409ee31fb2c67746 Mon Sep 17 00:00:00 2001 From: XukeWei-cc <301152382+XukeWei-cc@users.noreply.github.com> Date: Thu, 9 Jul 2026 19:52:56 +0800 Subject: [PATCH] Add main PR source branch guard --- .../workflows/validate-pr-source-branch.yml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/validate-pr-source-branch.yml diff --git a/.github/workflows/validate-pr-source-branch.yml b/.github/workflows/validate-pr-source-branch.yml new file mode 100644 index 0000000..fb868a1 --- /dev/null +++ b/.github/workflows/validate-pr-source-branch.yml @@ -0,0 +1,33 @@ +name: Validate PR Source Branch + +on: + pull_request: + branches: + - main + types: + - opened + - reopened + - synchronize + - edited + - ready_for_review + +permissions: + contents: read + +jobs: + validate-source-branch: + name: Validate PR source branch + runs-on: ubuntu-latest + steps: + - name: Require feature or fix branch + shell: bash + env: + HEAD_REF: ${{ github.head_ref }} + run: | + if [[ "$HEAD_REF" =~ ^(feature|fix)-.+$ ]]; then + echo "Allowed source branch: $HEAD_REF" + exit 0 + fi + + echo "PRs targeting main must come from a branch named feature-* or fix-*. Current source branch: $HEAD_REF" >&2 + exit 1