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"