From 1a83fc516e77dd838402ff1e7bbbada27c0d08f5 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 2 Aug 2026 20:26:47 +0530 Subject: [PATCH 1/4] ci(patch): fall back to develop when the base ref has no frappe branch The Patch Test fetches the frappe repo using this erpnext PR's base branch name. For an ordinary PR that is develop, which exists in frappe/frappe. For a stacked PR the base is an erpnext feature branch with no counterpart there, so the fetch fails and the step exits 128 before any patch runs: fatal: couldn't find remote ref pg-audit/bom-amount-per-line This affects every stacked PR. It has been latent rather than absent: earlier stacks passed only because their Patch Test ran while they still targeted develop, before being retargeted onto the layer below. Fall back to develop when the base ref does not resolve. Ordinary PRs and version-branch PRs are unaffected -- their base exists in frappe, so the first fetch succeeds and the fallback never runs. --- .github/workflows/patch.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index 83c2d7ff925..4b50c3b2043 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -171,7 +171,11 @@ jobs: update_to_version 16 3.14 echo "Updating to latest version" - git -C "apps/frappe" fetch --depth 1 upstream "${GITHUB_BASE_REF:-${GITHUB_REF##*/}}" + # a stacked PR's base is an erpnext feature branch with no counterpart in frappe, + # so fall back to the repository's default branch + base_ref="${GITHUB_BASE_REF:-${GITHUB_REF##*/}}" + git -C "apps/frappe" fetch --depth 1 upstream "$base_ref" \ + || git -C "apps/frappe" fetch --depth 1 upstream develop git -C "apps/frappe" checkout -q -f FETCH_HEAD git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA" From ccf54b58819cffb5694bcbb2cd2ea5af90024fed Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 2 Aug 2026 20:45:05 +0530 Subject: [PATCH 2/4] ci(patch): only fall back when the frappe branch is genuinely absent The previous `||` treated every fetch failure as a missing branch, so a transient network or auth error on a base that does exist in frappe would silently substitute develop and report Patch Test results against the wrong revision. Probe with `ls-remote --exit-code` instead: exit 2 means no matching ref, so fall back; any other non-zero status is a real failure and is re-raised. --- .github/workflows/patch.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index 4b50c3b2043..343e9767067 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -171,11 +171,17 @@ jobs: update_to_version 16 3.14 echo "Updating to latest version" - # a stacked PR's base is an erpnext feature branch with no counterpart in frappe, - # so fall back to the repository's default branch base_ref="${GITHUB_BASE_REF:-${GITHUB_REF##*/}}" - git -C "apps/frappe" fetch --depth 1 upstream "$base_ref" \ - || git -C "apps/frappe" fetch --depth 1 upstream develop + ls_remote_status=0 + git -C "apps/frappe" ls-remote --exit-code --heads upstream "$base_ref" >/dev/null \ + || ls_remote_status=$? + if [ "$ls_remote_status" -eq 2 ]; then + echo "frappe has no '$base_ref' branch; falling back to develop" + base_ref=develop + elif [ "$ls_remote_status" -ne 0 ]; then + exit "$ls_remote_status" + fi + git -C "apps/frappe" fetch --depth 1 upstream "$base_ref" git -C "apps/frappe" checkout -q -f FETCH_HEAD git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA" From 28d498012ae123088004c14bf896c0bce783c584 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 2 Aug 2026 22:04:48 +0530 Subject: [PATCH 3/4] ci(patch): resolve the frappe ref by type and only fall back for branches The probe used --heads with a bare name, so it could not describe a tag push and would have fallen back to develop for one. Resolve a fully qualified ref from the event instead: the PR base or pushed branch under refs/heads, a tag under refs/tags, and fail loudly on an unrecognised ref type. Only branch refs are eligible for the develop fallback. A tag that is absent from frappe is a real error, not a stacked-PR base, so it still fails. --- .github/workflows/patch.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index 343e9767067..f6c74bb5cc9 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -171,17 +171,30 @@ jobs: update_to_version 16 3.14 echo "Updating to latest version" - base_ref="${GITHUB_BASE_REF:-${GITHUB_REF##*/}}" + fallback_to_develop=0 + if [ -n "${GITHUB_BASE_REF:-}" ]; then + frappe_ref="refs/heads/$GITHUB_BASE_REF" + fallback_to_develop=1 + elif [ "${GITHUB_REF_TYPE:-}" = "branch" ]; then + frappe_ref="refs/heads/$GITHUB_REF_NAME" + fallback_to_develop=1 + elif [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then + frappe_ref="refs/tags/$GITHUB_REF_NAME" + else + echo "Unsupported GitHub ref type: '${GITHUB_REF_TYPE:-unset}'" + exit 1 + fi + ls_remote_status=0 - git -C "apps/frappe" ls-remote --exit-code --heads upstream "$base_ref" >/dev/null \ + git -C "apps/frappe" ls-remote --exit-code upstream "$frappe_ref" >/dev/null \ || ls_remote_status=$? - if [ "$ls_remote_status" -eq 2 ]; then - echo "frappe has no '$base_ref' branch; falling back to develop" - base_ref=develop + if [ "$ls_remote_status" -eq 2 ] && [ "$fallback_to_develop" -eq 1 ]; then + echo "frappe has no '$frappe_ref'; falling back to develop" + frappe_ref=refs/heads/develop elif [ "$ls_remote_status" -ne 0 ]; then exit "$ls_remote_status" fi - git -C "apps/frappe" fetch --depth 1 upstream "$base_ref" + git -C "apps/frappe" fetch --depth 1 upstream "$frappe_ref" git -C "apps/frappe" checkout -q -f FETCH_HEAD git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA" From 39b6f37a48aae0cc7891f1781f9bbb23e3fe1339 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sun, 2 Aug 2026 22:06:21 +0530 Subject: [PATCH 4/4] ci(patch): use GITHUB_REF instead of rebuilding it from type and name GITHUB_REF is already the fully qualified ref for both branch and tag events, so reconstructing refs/heads/$GITHUB_REF_NAME and refs/tags/$GITHUB_REF_NAME just risks the two drifting apart. Keep the type check, since it still decides whether the develop fallback applies, and take the ref verbatim. --- .github/workflows/patch.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index f6c74bb5cc9..e8eaa4f8ae4 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -176,10 +176,10 @@ jobs: frappe_ref="refs/heads/$GITHUB_BASE_REF" fallback_to_develop=1 elif [ "${GITHUB_REF_TYPE:-}" = "branch" ]; then - frappe_ref="refs/heads/$GITHUB_REF_NAME" + frappe_ref="$GITHUB_REF" fallback_to_develop=1 elif [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then - frappe_ref="refs/tags/$GITHUB_REF_NAME" + frappe_ref="$GITHUB_REF" else echo "Unsupported GitHub ref type: '${GITHUB_REF_TYPE:-unset}'" exit 1