Skip to content

Commit 456b529

Browse files
committed
update: handle PR branch checks
1 parent e4accb0 commit 456b529

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

hooks/check-branch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
source ./hooks/populate-hook-constants.sh
44

5-
isVersionBranch=$( if [[ ${currentBranch} =~ ^[0-9]+.[0-9]+$ ]]; then echo true; else echo false; fi )
5+
isVersionBranch=$( if [[ ${targetBranch} =~ ^[0-9]+.[0-9]+$ ]]; then echo true; else echo false; fi )
66

77
# Check that the code version matches the branch version if on a versioned branch
88
# `%.*` strips out the suffix after (and including) the last `.`
9-
if "$isVersionBranch" && [[ "${currentBranch%.*}" != "${newestVersion%.*}" ]]
9+
if "$isVersionBranch" && [[ "${targetBranch%.*}" != "${newestVersion%.*}" ]]
1010
then
11-
echo "Code version (${newestVersion%.*}) does not match branch (${currentBranch%.*}), unexpected."
11+
echo "Code version (${newestVersion%.*}) does not match branch (${targetBranch%.*}), unexpected."
1212
exit 1
1313
fi

hooks/populate-hook-constants.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ setupVersion=$(sed -n 's/ *version *= *["]\([0-9\.]*\).*/\1/p' setup.py )
99

1010
newestVersion=$( if [[ "$constantsVersion" > "$setupVersion" ]]; then echo "$constantsVersion"; else echo "$setupVersion"; fi )
1111

12-
currentBranch=$(git branch --show-current 2> /dev/null) || currentBranch="(unnamed branch)" # Get current branch
13-
currentBranch=${currentBranch##refs/heads/} # Remove refs/heads/ if present
12+
# Target branch of the PR.
13+
# Ideally, this is all we want to check.
14+
if [[ "$GITHUB_BASE_REF" != "" ]]
15+
then
16+
targetBranch="$GITHUB_BASE_REF"
17+
else # Fallback to current branch if not in a PR
18+
targetBranch=$(git branch --show-current 2> /dev/null) || targetBranch="(unnamed branch)" # Get current branch
19+
fi
20+
targetBranch=${targetBranch##refs/heads/} # Remove refs/heads/ if present

0 commit comments

Comments
 (0)