From f7be714467db82291ab6127daee371c63ca9d020 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 19 Jul 2024 02:21:53 +0200 Subject: [PATCH] gha: check-pr-branch: verify major version only We'll be using release branches for minor version updates, so instead of (e.g.) a 27.0 branch, we'll be using 27.x and continue using the branch for minor version updates. This patch changes the validation step to only compare against the major version. Co-authored-by: Cory Snider Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 6d8fcbb2331b3cfdf64db1ed7b8665ac396f70db) Signed-off-by: Sebastiaan van Stijn --- .github/workflows/validate-pr.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index 12ab7c076ddd..ca00ec58cea7 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -53,10 +53,16 @@ jobs: # Backports or PR that target a release branch directly should mention the target branch in the title, for example: # [X.Y backport] Some change that needs backporting to X.Y # [X.Y] Change directly targeting the X.Y branch - - name: Get branch from PR title + - name: Check release branch id: title_branch - run: echo "$PR_TITLE" | sed -n 's/^\[\([0-9]*\.[0-9]*\)[^]]*\].*/branch=\1/p' >> $GITHUB_OUTPUT + run: | + # get the intended major version prefix ("[27.1 backport]" -> "27.") from the PR title. + [[ "$PR_TITLE" =~ ^\[([0-9]*\.)[^]]*\] ]] && branch="${BASH_REMATCH[1]}" - - name: Check release branch - if: github.event.pull_request.base.ref != steps.title_branch.outputs.branch && !(github.event.pull_request.base.ref == 'master' && steps.title_branch.outputs.branch == '') - run: echo "::error::PR title suggests targetting the ${{ steps.title_branch.outputs.branch }} branch, but is opened against ${{ github.event.pull_request.base.ref }}" && exit 1 + # get major version prefix from the release branch ("27.x -> "27.") + [[ "$GITHUB_BASE_REF" =~ ^([0-9]*\.) ]] && target_branch="${BASH_REMATCH[1]}" || target_branch="$GITHUB_BASE_REF" + + if [[ "$target_branch" != "$branch" ]] && ! [[ "$GITHUB_BASE_REF" == "master" && "$branch" == "" ]]; then + echo "::error::PR is opened against the $GITHUB_BASE_REF branch, but its title suggests otherwise." + exit 1 + fi