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"}