From 8126faa45224abd45acbf0e25ae04d1253cfd531 Mon Sep 17 00:00:00 2001 From: Cheney <970320820@qq.com> Date: Tue, 12 May 2026 16:07:04 +0800 Subject: [PATCH] fix(cli): detect and guide recovery of unpushed release artifacts Add pre-flight check in publish-cli.sh to detect unpushed commits and tags from previous failed pushes. When detected, the script exits with clear recovery instructions: 1. Retry push (for transient network failures) 2. Rollback and re-release (for clean restart) This prevents the baseline sync logic from skipping failed versions when local tags participate in version calculation after a push failure. Addresses feedback from dongmucat in PR #422. --- scripts/publish-cli.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/scripts/publish-cli.sh b/scripts/publish-cli.sh index a68674fe..0e9c31b9 100755 --- a/scripts/publish-cli.sh +++ b/scripts/publish-cli.sh @@ -54,6 +54,47 @@ git -C "$REPO_ROOT" pull --ff-only origin "$CURRENT_BRANCH" log_stage "fetching tags from origin" git -C "$REPO_ROOT" fetch --tags --prune origin +log_stage "checking for unpushed release artifacts" +UNPUSHED_COMMITS="$(git -C "$REPO_ROOT" log --oneline origin/"$CURRENT_BRANCH"..HEAD 2>/dev/null || true)" +UNPUSHED_RELEASE_TAGS="$(git -C "$REPO_ROOT" tag --list 'cli-v*' --no-merged origin/"$CURRENT_BRANCH" 2>/dev/null || true)" + +if [[ -n "$UNPUSHED_COMMITS" ]] || [[ -n "$UNPUSHED_RELEASE_TAGS" ]]; then + echo "" >&2 + echo "ERROR: Detected unpushed release artifacts from a previous failed push:" >&2 + echo "" >&2 + + if [[ -n "$UNPUSHED_COMMITS" ]]; then + echo " Unpushed commits:" >&2 + echo "$UNPUSHED_COMMITS" | sed 's/^/ /' >&2 + echo "" >&2 + fi + + if [[ -n "$UNPUSHED_RELEASE_TAGS" ]]; then + echo " Unpushed tags:" >&2 + echo "$UNPUSHED_RELEASE_TAGS" | sed 's/^/ /' >&2 + echo "" >&2 + fi + + echo "Choose a recovery option:" >&2 + echo "" >&2 + echo " 1. Retry push (if the previous failure was temporary, e.g., network issue):" >&2 + if [[ -n "$UNPUSHED_RELEASE_TAGS" ]]; then + FIRST_TAG="$(echo "$UNPUSHED_RELEASE_TAGS" | head -n1)" + echo " git push origin $CURRENT_BRANCH $FIRST_TAG" >&2 + else + echo " git push origin $CURRENT_BRANCH" >&2 + fi + echo "" >&2 + echo " 2. Rollback and retry release (if you want to start fresh):" >&2 + if [[ -n "$UNPUSHED_RELEASE_TAGS" ]]; then + echo " git tag -d $UNPUSHED_RELEASE_TAGS" | tr '\n' ' ' | sed 's/ $/\n/' >&2 + fi + echo " git reset --hard origin/$CURRENT_BRANCH" >&2 + echo " # Then re-run: make publish-cli" >&2 + echo "" >&2 + exit 1 +fi + log_stage "resolving baseline version from latest cli-v* tag" LATEST_TAG="$(git -C "$REPO_ROOT" tag --list 'cli-v*' --sort=-version:refname | head -n1)" if [[ -n "$LATEST_TAG" ]]; then