Skip to content

Commit

Permalink
FIX Handle pulls/4/mybranch style branches
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 1, 2022
1 parent e5be049 commit 5d385c3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,25 @@ jobs:
if [[ $GITHUB_BASE_REF != "" ]]; then
BRANCH_OR_TAG=$GITHUB_BASE_REF
fi
if [[ $BRANCH_OR_TAG =~ ^[1-9]$ ]] || [[ $BRANCH_OR_TAG =~ ^[0-9]\.[0-9]+$ ]]; then
export COMPOSER_ROOT_VERSION="${BRANCH_OR_TAG}.x-dev"
# This extract the version from the following branch naming conventions:
# pulls/x/mybranch style is common on push events to creative-commoners account
# 4 => 4
# 4.10 => 4.10
# pulls/4/mybranch => 4
# pulls/4.10/mybranch => 4.10
if [[ $BRANCH_OR_TAG =~ ^([1-9]+)$ ]] || \
[[ $BRANCH_OR_TAG =~ ^([0-9]+\.[0-9]+)$ ]] || \
[[ $BRANCH_OR_TAG =~ ^pulls/([1-9]+)/.+$ ]] || \
[[ $BRANCH_OR_TAG =~ ^pulls/([0-9]+\.[0-9]+)/.+$ ]]; \
then
export COMPOSER_ROOT_VERSION="${BASH_REMATCH[1]}.x-dev"
elif [[ $BRANCH_OR_TAG =~ ^[0-9]\.[0-9]+\.[0-9]+ ]]; then
export COMPOSER_ROOT_VERSION="${BRANCH_OR_TAG}"
else
export COMPOSER_ROOT_VERSION="dev-${BRANCH_OR_TAG}"
# e.g. push event to branch called myaccount-patch-1
# use git history to make a best attempt at getting the parent branch
PARENT_BRANCH=$(git show-branch -a 2>/dev/null | grep '\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
export COMPOSER_ROOT_VERSION="${PARENT_BRANCH}.x-dev"
fi
echo "BRANCH_OR_TAG is $BRANCH_OR_TAG"
echo "COMPOSER_ROOT_VERSION is $COMPOSER_ROOT_VERSION"
Expand Down

0 comments on commit 5d385c3

Please sign in to comment.