Browse code

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 <corhere@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/07/18 07:44:40
Showing 1 changed files
... ...
@@ -53,10 +53,16 @@ jobs:
53 53
       # Backports or PR that target a release branch directly should mention the target branch in the title, for example:
54 54
       # [X.Y backport] Some change that needs backporting to X.Y
55 55
       # [X.Y] Change directly targeting the X.Y branch
56
-      - name: Get branch from PR title
56
+      - name: Check release branch
57 57
         id: title_branch
58
-        run: echo "$PR_TITLE" | sed -n 's/^\[\([0-9]*\.[0-9]*\)[^]]*\].*/branch=\1/p' >> $GITHUB_OUTPUT
58
+        run: |
59
+          # get the intended major version prefix ("[27.1 backport]" -> "27.") from the PR title.
60
+          [[ "$PR_TITLE" =~ ^\[\([0-9]*\.\)[^]]*\] ]] && branch="${BASH_REMATCH[1]}"
59 61
 
60
-      - name: Check release branch
61
-        if: github.event.pull_request.base.ref != steps.title_branch.outputs.branch && !(github.event.pull_request.base.ref == 'master' && steps.title_branch.outputs.branch == '')
62
-        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
62
+          # get major version prefix from the release branch ("27.x -> "27.")
63
+          [[ "$GITHUB_BASE_REF" =~ ^\([0-9]*\.\) ]] && target_branch="${BASH_REMATCH[1]}"
64
+
65
+          if [[ "$GITHUB_BASE_REF" != "$branch" ]] && ! [[ "$GITHUB_BASE_REF" == "master" && "$branch" == "" ]]; then
66
+              echo "::error::PR is opened against the $GITHUB_BASE_REF branch, but its title suggests otherwise."
67
+              exit 1
68
+          fi