From e56b19e88daa1b9d384183acdaf1eb1a642d35b9 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 1 Jul 2022 12:34:53 +1200 Subject: [PATCH] FIX Detect COMPOSER_ROOT_VERSION on push events --- .github/workflows/ci.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d9c7ca..da59fcf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 extracts the version from common branch naming conventions + # pulls/x/mybranch style is used 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"