From febf379f19f43ef3b9bfec629b426af532a7be8e Mon Sep 17 00:00:00 2001 From: Martin Mulholland <71444914+mmulholla@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:32:09 -0400 Subject: [PATCH] test.mk get PR branch from CLONEREFS_OPTIONS (#887) * test.mk get PR branch from CLONEREFS_OPTIONS * add refs/heads/ to branch from CLONEREF_OPTIONS * get and use PR branch from CLONEREF_OPTIONS * trying things * trying things 2 * trying things 3 * possible solution * attempt to fix error * solution * fix non github action path --------- Co-authored-by: Matous Jobanek Co-authored-by: Francisc Munteanu --- make/test.mk | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/make/test.mk b/make/test.mk index e5c8d2bd2..180aab033 100644 --- a/make/test.mk +++ b/make/test.mk @@ -97,29 +97,26 @@ ifeq ($(E2E_REPO_PATH),"") git clone https://github.com/codeready-toolchain/toolchain-e2e.git ${E2E_REPO_PATH} ifneq ($(CI),) ifneq ($(GITHUB_ACTIONS),) - $(eval BRANCH_REF = refs/heads/${GITHUB_HEAD_REF}) + $(eval BRANCH_NAME = ${GITHUB_HEAD_REF}) $(eval AUTHOR_LINK = https://github.com/${AUTHOR}) else $(eval AUTHOR_LINK = $(shell jq -r '.refs[0].pulls[0].author_link' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]')) - @echo "using pull sha ${PULL_PULL_SHA}" - # get branch ref of the fork the PR was created from - $(eval BRANCH_REF := $(shell curl ${AUTHOR_LINK}/host-operator.git/info/refs?service=git-upload-pack --output - /dev/null 2>&1 | grep -a ${PULL_PULL_SHA} | awk '{print $$2}')) + @echo "found author link ${AUTHOR_LINK}" + $(eval BRANCH_NAME := $(shell jq -r '.refs[0].pulls[0].head_ref' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]')) endif @echo "using author link ${AUTHOR_LINK}" - @echo "detected branch ref ${BRANCH_REF}" + @echo "detected branch ${BRANCH_NAME}" # check if a branch with the same ref exists in the user's fork of toolchain-e2e repo - $(eval REMOTE_E2E_BRANCH := $(shell curl ${AUTHOR_LINK}/toolchain-e2e.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "${BRANCH_REF}$$" | awk '{print $$2}')) + $(eval REMOTE_E2E_BRANCH := $(shell curl ${AUTHOR_LINK}/toolchain-e2e.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}')) @echo "branch ref of the user's fork: \"${REMOTE_E2E_BRANCH}\" - if empty then not found" # check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master if [[ -n "${REMOTE_E2E_BRANCH}" ]]; then \ git config --global user.email "devtools@redhat.com"; \ git config --global user.name "Devtools"; \ - # retrieve the branch name \ - BRANCH_NAME=`echo ${BRANCH_REF} | awk -F'/' '{print $$3}'`; \ # add the user's fork as remote repo \ git --git-dir=${E2E_REPO_PATH}/.git --work-tree=${E2E_REPO_PATH} remote add external ${AUTHOR_LINK}/toolchain-e2e.git; \ # fetch the branch \ - git --git-dir=${E2E_REPO_PATH}/.git --work-tree=${E2E_REPO_PATH} fetch external ${BRANCH_REF}; \ + git --git-dir=${E2E_REPO_PATH}/.git --work-tree=${E2E_REPO_PATH} fetch external ${REMOTE_E2E_BRANCH}; \ # merge the branch with master \ git --git-dir=${E2E_REPO_PATH}/.git --work-tree=${E2E_REPO_PATH} merge --allow-unrelated-histories --no-commit FETCH_HEAD; \ fi;