Commit 040c6f82 authored by xuwang's avatar xuwang
Browse files

fix(upgrade-check): nudge whenever HEAD is not the latest release



The check classified by branch-vs-tag, so a branch tip coinciding with a
release tag (e.g. main right after a release) was mis-read as "pinned to
latest" and went silent. Gate on the actual commit instead: stay silent
only when HEAD is exactly the latest release commit, and nudge in every
other state -- unpinned branch, older tag pin, or a non-release commit
(which now gets a "not on a release" hint).

Changelog: fixed
Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent dac078df
Loading
Loading
Loading
Loading
+30 −18
Original line number Diff line number Diff line
#!/bin/bash
# otica-upgrade-check.sh
# Non-blocking, release-aware check of the local OTICA checkout. Compares the
# current checkout against the latest v* release tag and prints an upgrade notice
# if a newer release exists (pinned) or if the project is tracking main unpinned.
# Non-blocking, release-aware check of the local OTICA checkout. Prints an
# upgrade notice whenever HEAD is not exactly the latest v* release commit --
# an older pin, an unpinned branch, or any non-release commit -- and stays
# silent only when the checkout is on the latest release.
# A throttled background `git fetch --tags` keeps the *next* run current without
# ever blocking `make help` on the network. Never fails the caller.

@@ -26,25 +27,36 @@ git_otica() { git -C "${OTICA_DIR}" "$@"; }
latest_tag=$(git_otica tag --list 'v*' --sort=-v:refname 2>/dev/null | head -n1)

if [ -n "${latest_tag}" ]; then
    # What is the checkout currently on? An exact tag = pinned; otherwise a branch.
    current_tag=$(git_otica describe --tags --exact-match 2>/dev/null || true)
    current_branch=$(git_otica symbolic-ref --quiet --short HEAD 2>/dev/null || true)
    # The only "all good, stay silent" state is being exactly on the latest
    # release commit (whether detached on its tag or a branch tip that happens to
    # sit there). Every other checkout -- an older pin, an unpinned branch, or a
    # non-release commit -- is "not on the latest release" and gets nudged.
    head_sha=$(git_otica rev-parse -q --verify HEAD 2>/dev/null || true)
    latest_sha=$(git_otica rev-parse -q --verify "${latest_tag}^{commit}" 2>/dev/null || true)

    if [ -n "${current_tag}" ]; then
        # Pinned to a tag: notify only if a strictly newer release exists.
        newest=$(printf '%s\n%s\n' "${current_tag#v}" "${latest_tag#v}" | sort -V | tail -n1)
        if [ "${current_tag}" != "${latest_tag}" ] && [ "${newest}" = "${latest_tag#v}" ]; then
            echo
            echo -e "${YELLOW}==== OTICA release ${latest_tag} available ====${NC}"
            echo -e "Pinned to ${YELLOW}${current_tag}${NC}. Review the CHANGELOG, then bump"
            echo -e "${GREEN}OTICA_VERSION=${latest_tag}${NC} and run ${GREEN}make update-otica${NC}."
        fi
    elif [ -n "${current_branch}" ]; then
    if [ -n "${head_sha}" ] && [ "${head_sha}" = "${latest_sha}" ]; then
        :   # On the latest release -- nothing to report.
    else
        current_branch=$(git_otica symbolic-ref --quiet --short HEAD 2>/dev/null || true)
        current_tag=$(git_otica describe --tags --exact-match 2>/dev/null || true)
        if [ -n "${current_branch}" ]; then
            # Unpinned (tracking a branch): nudge toward pinning to the latest release.
            echo
            echo -e "${YELLOW}==== OTICA is unpinned (tracking ${current_branch}) ====${NC}"
            echo -e "Latest release is ${GREEN}${latest_tag}${NC}. Pin it to avoid surprise"
            echo -e "framework changes: set ${GREEN}OTICA_VERSION=${latest_tag}${NC} in env.mk."
        else
            # Detached but not on the latest release: pinned to an older tag, a SHA,
            # or some other commit. Point at the newest release either way.
            echo
            echo -e "${YELLOW}==== OTICA release ${latest_tag} available ====${NC}"
            if [ -n "${current_tag}" ]; then
                echo -e "Pinned to ${YELLOW}${current_tag}${NC}. Review the CHANGELOG, then bump"
            else
                echo -e "Checkout is not on a release. Review the CHANGELOG, then set"
            fi
            echo -e "${GREEN}OTICA_VERSION=${latest_tag}${NC} and run ${GREEN}make update-otica${NC}."
        fi
    fi
fi