Repository navigation
fix(release): consider every tag on the latest release commit - #46671
Dhairya-007 wants to merge 1 commit into
Conversation
`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.
3737e03 to
63f0177
Compare
|
|
||
| # Iterate through the tags of the latest release | ||
| for tag in $TAGS | ||
| for tag in "${TAGS[@]}" |
There was a problem hiding this comment.
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
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 fixThere was a problem hiding this comment.
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.
| for tag in "${TAGS[@]}" | |
| for tag in $(printf '%s\n' "${TAGS[@]}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) |
aminghadersohi
left a comment
There was a problem hiding this comment.
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.
| tag, latest_tag_list="(HEAD -> master, tag: 2.1.0, tag: latest)" | ||
| ) | ||
|
|
||
| assert expected_output in result.stdout |
There was a problem hiding this comment.
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.
| 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 |
SUMMARY
scripts/tag_latest_release.shdecides whether the tag being released is newer than the release currently carrying thelatesttag. It collects the decorations of that commit into theTAGSarray and then loops over them with:$TAGSis 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 fromgit 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 withHEAD -> master, the loop rejects that as a non-version tag, never reaches the actual version tag, and the script falls through toVersions are equaland writesSKIP_TAG=true— so thelatesttag silently stays on the previous release.Fix is
for tag in "${TAGS[@]}".docker/tag_latest_release.shis 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_releasekeeps its current signature and default environment, so the existingassert_called_once_withassertion is unaffected.TESTING INSTRUCTIONS
Reproduction with the unpatched script, a decoration that leads with a branch:
Same input, patched:
Then run the suite:
The three new cases pass with the fix and fail without it; the eight pre-existing cases still pass.
ADDITIONAL INFORMATION
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.