Skip to content

fix(release): consider every tag on the latest release commit - #46671

Open
Dhairya-007 wants to merge 1 commit into
apache:masterfrom
Dhairya-007:fix/tag-latest-release-all-tags
Open

Dhairya-007 wants to merge 1 commit into
apache:masterfrom
Dhairya-007:fix/tag-latest-release-all-tags

Conversation

@Dhairya-007

Copy link
Copy Markdown

SUMMARY

scripts/tag_latest_release.sh decides whether the tag being released is newer than the release currently carrying the latest tag. It collects the decorations of that commit into the TAGS array and then loops over them with:

TAGS=($(split_string "$LATEST_TAGS" " "))
...
for tag in $TAGS

$TAGS is an unsubscripted array expansion, so it yields only ${TAGS[0]}. The loop therefore inspects exactly one decoration and ignores the rest.

That matters because the list does not come from git tag, it comes from git show --pretty=tformat:%d, which decorates a commit with branch names as well as tags. When the released commit is also a branch tip, the decoration starts with HEAD -> master, the loop rejects that as a non-version tag, never reaches the actual version tag, and the script falls through to Versions are equal and writes SKIP_TAG=true — so the latest tag silently stays on the previous release.

Fix is for tag in "${TAGS[@]}". docker/tag_latest_release.sh is a byte-identical copy of the script and gets the same change.

The existing test suite did not catch this because the mocked decoration happens to put the version tag first. The mock is now overridable through TEST_LATEST_TAG_LIST, and a regression test covers a branch-decorated commit. BashMock.tag_latest_release keeps its current signature and default environment, so the existing assert_called_once_with assertion is unaffected.

TESTING INSTRUCTIONS

Reproduction with the unpatched script, a decoration that leads with a branch:

$ TEST_ENV=true GITHUB_OUTPUT=/tmp/out \
  TEST_LATEST_TAG_LIST="(HEAD -> master, tag: 2.1.0, tag: latest)" \
  ./scripts/tag_latest_release.sh 2.1.1 --dry-run
LATEST_RELEASE_TAG: HEAD
'Latest' has been associated with tag HEAD which is not a valid release version. Looking for another.
Versions are equal          # wrong: 2.1.1 > 2.1.0, and SKIP_TAG=true

Same input, patched:

Comparing 2 to 2
Comparing 1 to 1
Comparing 1 to 0
This release tag 2.1.1 is newer than the latest.

Then run the suite:

pytest tests/unit_tests/scripts/tag_latest_release_test.py

The three new cases pass with the fix and fail without it; the eight pre-existing cases still pass.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
  • Introduces new feature or API
  • Removes existing feature or API

Release-tooling only; no runtime code is touched.

Claude Code assisted in writing this patch. The reproduction and the test runs quoted above were executed locally against this branch, and I reviewed the change before opening the PR.

`tag_latest_release.sh` collects the tags that decorate the commit currently
tagged `latest` into the `TAGS` array, then iterates it with `for tag in
$TAGS`. An unquoted, unsubscripted array expansion yields only the first
element, so the loop examines exactly one decoration.

`git show --pretty=tformat:%d` decorates a commit with branch names as well as
tags, so the first entry is frequently not a version tag. When the released
commit is also the tip of a branch the list starts with `HEAD -> master`, the
loop rejects it as a non-version tag, never reaches the real version tag, and
the script falls through to "Versions are equal" and sets `SKIP_TAG=true` -
leaving the `latest` tag on the previous release.

Iterate `"${TAGS[@]}"` instead. The existing mock happens to put the version
tag first, which is why the suite did not catch this; the mocked decoration is
now overridable via `TEST_LATEST_TAG_LIST` and a regression test covers a
branch-decorated commit.

`docker/tag_latest_release.sh` is a byte-identical copy of the script, so it
carries the same fix.
@Dhairya-007
Dhairya-007 force-pushed the fix/tag-latest-release-all-tags branch from 3737e03 to 63f0177 Compare November 28, 2026 08:24

# Iterate through the tags of the latest release
for tag in $TAGS
for tag in "${TAGS[@]}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: When decorations contain multiple version tags, each iteration overwrites compare_result; 3.0.0 followed by 2.1.0 makes candidate 2.5.0 appear newer and can move latest backwards.

Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** scripts/tag_latest_release.sh
**Line:** 143:143
**Comment:**
	*Logic Error: When decorations contain multiple version tags, each iteration overwrites `compare_result`; `3.0.0` followed by `2.1.0` makes candidate `2.5.0` appear newer and can move `latest` backwards.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced at 63f0177 with real git: a commit tagged 3.0.0, 2.1.0 and latest decorates as (tag: latest, tag: 3.0.0, tag: 2.1.0), so release 2.5.0 prints "newer" with SKIP_TAG=false. Comparing only against the highest X.Y.Z tag avoids that; docker/tag_latest_release.sh needs the same line.

Suggested change
for tag in "${TAGS[@]}"
for tag in $(printf '%s\n' "${TAGS[@]}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • In both script copies, each version decoration overwrites the prior comparison; with tags 3.0.0 and 2.1.0, candidate 2.5.0 can incorrectly advance latest.
  • The new test covers multiple decorations but only one version tag, so it does not exercise this case.

Assessed commit: 63f0177a375c

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop fix is right. The open line-143 point still applies: with two release tags on the latest commit the lowest one decides, so latest can move backwards, in both script copies.

Comment on lines +82 to +85
tag, latest_tag_list="(HEAD -> master, tag: 2.1.0, tag: latest)"
)

assert expected_output in result.stdout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Real git lists tag: latest before the version tag, the order that made the old loop skip on every run. The 2.1.0 case also passes with the fix reverted, since "Versions are equal" is the no-tag fallthrough; asserting the found version makes it fail.

Suggested change
tag, latest_tag_list="(HEAD -> master, tag: 2.1.0, tag: latest)"
)
assert expected_output in result.stdout
tag, latest_tag_list="(HEAD -> master, tag: latest, tag: 2.1.0)"
)
assert "The current release with the latest tag is version 2.1.0" in result.stdout
assert expected_output in result.stdout

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docker risk:ci-script PR modifies scripts that execute in CI (supply chain risk) size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants