From c826f8896fb63cb7e4064a9926b22e21f0fd51e5 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 1 May 2025 09:40:19 -0400 Subject: [PATCH] Create prevent-main-target.yml Prevents pull requests from targeting `main`. --- .github/workflows/prevent-main-target.yml | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/prevent-main-target.yml diff --git a/.github/workflows/prevent-main-target.yml b/.github/workflows/prevent-main-target.yml new file mode 100644 index 00000000..3b4d4630 --- /dev/null +++ b/.github/workflows/prevent-main-target.yml @@ -0,0 +1,25 @@ +# This workflow prevents pull requests from targeting the 'main' branch. +name: Prevent PRs Targeting Main +on: + pull_request: + types: + - opened + - reopened + - synchronize + - edited +jobs: + check_base_branch: + name: Check Target Branch + runs-on: ubuntu-latest + steps: + - name: Target Branch Check + if: github.event.pull_request.base.ref == 'main' + run: | + echo "::error::Pull requests targeting the 'main' branch are not allowed." + echo "Please change the target branch of this PR to 'develop' or a feature branch." + exit 1 + - name: Target branch is allowed + if: github.event.pull_request.base.ref != 'main' + run: | + echo "Target branch (${{ github.event.pull_request.base.ref }}) is allowed. We good." + exit 0