diff --git a/.github/workflows/check-pr-target-branch.yml b/.github/workflows/check-pr-target-branch.yml new file mode 100644 index 000000000..c6a2479c8 --- /dev/null +++ b/.github/workflows/check-pr-target-branch.yml @@ -0,0 +1,31 @@ +name: Check PR target branch + +on: + pull_request: + types: [opened, edited, reopened, synchronize, ready_for_review] + +permissions: {} + +jobs: + check-pr-target-branch: + name: Check PR target branch + runs-on: ubuntu-slim + + steps: + - name: Validate source and target branch + shell: bash + env: + SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }} + TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} + run: | + echo "Source branch: ${SOURCE_BRANCH}" + echo "Target branch: ${TARGET_BRANCH}" + + main_target_branch_regex='^[0-9]+\.[0-9]+\.[0-9]+/(release)$' + + if [[ "${TARGET_BRANCH}" == "main" && ! "${SOURCE_BRANCH}" =~ ${main_target_branch_regex} ]]; then + echo "::warning title=Wrong PR target branch::Branch '${SOURCE_BRANCH}' targets 'main'. Only '/release' branches are expected to target 'main'. Feature and fix branches should target their matching release branch instead, for example '2.5.2/release'." + exit 1 + fi + + echo "PR target branch looks OK."