Browse code

gha: check-pr-branch: fix branch check regression

This check was updated in f460110ef571fba172d8962d64e2fc58bdf53e97, but
introduced some bugs;

- the regular expressions were meant to define a capturing group, but
the braces (`(`, `)`) were escaped (they previously were used by
`sed`, which requires different escaping), so no value was captured.
- the check itself was not updated to use the resulting `$target_branch`
env-var, so was comparing against the `$GITHUB_BASE_REF` (which is
the branch name before stripping minor versions).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/07/19 19:26:17
Showing 1 changed files
... ...
@@ -57,12 +57,12 @@ jobs:
57 57
         id: title_branch
58 58
         run: |
59 59
           # get the intended major version prefix ("[27.1 backport]" -> "27.") from the PR title.
60
-          [[ "$PR_TITLE" =~ ^\[\([0-9]*\.\)[^]]*\] ]] && branch="${BASH_REMATCH[1]}"
60
+          [[ "$PR_TITLE" =~ ^\[([0-9]*\.)[^]]*\] ]] && branch="${BASH_REMATCH[1]}"
61 61
 
62 62
           # get major version prefix from the release branch ("27.x -> "27.")
63
-          [[ "$GITHUB_BASE_REF" =~ ^\([0-9]*\.\) ]] && target_branch="${BASH_REMATCH[1]}"
63
+          [[ "$GITHUB_BASE_REF" =~ ^([0-9]*\.) ]] && target_branch="${BASH_REMATCH[1]}" || target_branch="$GITHUB_BASE_REF"
64 64
 
65
-          if [[ "$GITHUB_BASE_REF" != "$branch" ]] && ! [[ "$GITHUB_BASE_REF" == "master" && "$branch" == "" ]]; then
65
+          if [[ "$target_branch" != "$branch" ]] && ! [[ "$GITHUB_BASE_REF" == "master" && "$branch" == "" ]]; then
66 66
               echo "::error::PR is opened against the $GITHUB_BASE_REF branch, but its title suggests otherwise."
67 67
               exit 1
68 68
           fi