From 6be6bf292978b07fae555097cf6bbdcb8953f423 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 1 Aug 2026 15:08:14 +0530 Subject: [PATCH] ci: fall back to develop when frappe has no matching branch (#57693) * ci: fall back to develop when frappe has no matching branch The frappe branch to install is taken from the pull request's base branch. A stacked pull request targets another erpnext branch, so the clone fails with "couldn't find remote ref", no bench is installed, and every job that needs one fails with it. Fall back to develop when the base branch does not exist in frappe. An explicit FRAPPE_BRANCH is left alone, since it can be a commit sha rather than a branch. * ci: only fall back when frappe is known to lack the branch git ls-remote --exit-code reports 2 for a branch that is not there and 128 for a remote it could not reach. Treating both as absence let a transient network or DNS failure install develop over the branch the pull request was built against. Fall back on 2 alone and log anything else, so a flaky probe leaves the branch as it was. --- .github/helper/install.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index 27928ee8bbc..1abcd7683e7 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -6,7 +6,27 @@ cd ~ || exit githubbranch=${GITHUB_BASE_REF:-${GITHUB_REF##*/}} frappeuser=${FRAPPE_USER:-"frappe"} -frappecommitish=${FRAPPE_BRANCH:-$githubbranch} +frappecommitish=${FRAPPE_BRANCH:-} + +# A stacked pull request targets another erpnext branch, which has no counterpart in frappe. +# Fall back to develop so the bench is still installed. An explicit FRAPPE_BRANCH is trusted as +# given, since it can be a commit sha rather than a branch. +if [ -z "$frappecommitish" ]; then + frappecommitish=$githubbranch + + # git ls-remote --exit-code reports 2 for a branch that is not there and 128 for a remote it + # could not reach. Only the first one is proof of absence; keep the branch on anything else so + # a flaky probe cannot install an unrelated frappe. + probe=0 + git ls-remote --exit-code --heads "https://github.com/${frappeuser}/frappe" "$frappecommitish" >/dev/null 2>&1 || probe=$? + + if [ "$probe" -eq 2 ]; then + echo "frappe has no branch ${frappecommitish}, falling back to develop" + frappecommitish=develop + elif [ "$probe" -ne 0 ]; then + echo "could not reach frappe to check for branch ${frappecommitish} (git ls-remote exited ${probe}), keeping it" + fi +fi db_host=${DB_HOST:-"127.0.0.1"} db_user_host=${DB_USER_HOST:-"localhost"} wkhtmltox_deb=${WKHTMLTOX_DEB:-"/tmp/wkhtmltox.deb"}