@@ -135,25 +135,42 @@ jobs:
135135 # A maintenance release for an older line (e.g. v0.3.4 after
136136 # v0.4.0) must not move 'latest' backward; re-checked against
137137 # fresh gh-pages state on every attempt since release builds are
138- # not serialized. Dispatches honor the explicit input
138+ # not serialized. Dispatches honor the explicit input.
139+ # Returns 0 = may move, 1 = older line, 2 = could not verify —
140+ # fail closed, except for a confirmed-absent gh-pages (bootstrap)
139141 may_move_latest() {
140142 [[ "$GUARD_LATEST" == "true" ]] || return 0
141- git fetch --quiet origin gh-pages 2>/dev/null || return 0
143+ if ! git fetch --quiet origin gh-pages 2>/dev/null; then
144+ rc=0
145+ git ls-remote --exit-code origin refs/heads/gh-pages >/dev/null 2>&1 || rc=$?
146+ [[ "$rc" -eq 2 ]] && return 0
147+ echo "Cannot verify the current latest target; failing this attempt" >&2
148+ return 2
149+ fi
142150 current="$(git show FETCH_HEAD:versions.json 2>/dev/null \
143- | jq -r '.[] | select(.aliases | index("latest")) | .version' || true)"
151+ | jq -r '.[] | select(.aliases | index("latest")) | .version')" || {
152+ echo "Cannot read versions.json from gh-pages; failing this attempt" >&2
153+ return 2
154+ }
144155 if [[ -n "$current" ]] && \
145156 [[ "$(printf '%s\n%s\n' "$current" "$VERSION" | sort -V | tail -1)" != "$VERSION" ]]; then
146157 echo "Line ${VERSION} is older than current latest (${current}); not moving the alias" >&2
147158 return 1
148159 fi
149160 }
150161 deploy() {
151- if [[ "$LATEST" == "true" ]] && may_move_latest; then
152- mike deploy --push --update-aliases --title "$TITLE" "$VERSION" latest &&
153- mike set-default --push latest
154- else
162+ if [[ "$LATEST" != "true" ]]; then
155163 mike deploy --push --title "$TITLE" "$VERSION"
164+ return
156165 fi
166+ rc=0
167+ may_move_latest || rc=$?
168+ case "$rc" in
169+ 0) mike deploy --push --update-aliases --title "$TITLE" "$VERSION" latest &&
170+ mike set-default --push latest ;;
171+ 1) mike deploy --push --title "$TITLE" "$VERSION" ;;
172+ *) return 2 ;;
173+ esac
157174 }
158175 # Concurrent runs race on the gh-pages push; each attempt re-fetches
159176 # the branch, so retrying resolves the race
0 commit comments