Skip to content

fix(scripts): add smg-grpc-servicer to version check and fix pyproject.toml support - #683

Merged
slin1237 merged 4 commits into
mainfrom
chang/fix-version-check-grpc
Mar 10, 2026
Merged

slin1237 merged 4 commits into
mainfrom
chang/fix-version-check-grpc

Conversation

@CatherineSue

@CatherineSue CatherineSue commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

The check_release_versions.sh script was missing smg-grpc-servicer from its PYTHON_PACKAGES registry, so version bumps for the gRPC servicer were never checked during releases.

Additionally, the existing smg-grpc-proto entry pointed at __init__.py which uses importlib.metadata.version() — the script's sed extraction was pulling out the package name (smg-grpc-proto) instead of the actual version number, so bump detection never worked for it either.

Solution

  • Add smg-grpc-servicer to PYTHON_PACKAGES
  • Switch both entries to read version from pyproject.toml (the source of truth)
  • Update get_python_version, get_python_version_at_ref, and set_python_version to handle .toml files alongside __init__.py

Changes

  • Point smg-grpc-proto version file at pyproject.toml instead of __init__.py
  • Add smg-grpc-servicer|grpc_servicer|grpc_servicer/pyproject.toml entry
  • Add .toml branch to version get/set helpers using the same grep -m1 '^version' pattern used for Cargo.toml

Test Plan

  • Verified grep -m1 '^version' pyproject.toml | sed ... extracts 0.4.2 for both packages
  • Existing __init__.py codepath is preserved for any future packages that use hardcoded __version__
Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated

Summary by CodeRabbit

  • Chores
    • Version tooling now supports TOML-based Python package configs in addition to legacy version formats.
    • Improved detection of non-version edits and moved files, so changelog and version-bump decisions better reflect meaningful changes.
    • Safer read/update of package versions with validation and smarter fallbacks to the appropriate version source.

@CatherineSue
CatherineSue requested a review from slin1237 as a code owner March 9, 2026 18:39
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical issues in the release version checking script by expanding its coverage to include a previously overlooked gRPC servicer and rectifying an incorrect version extraction method for an existing package. The core change involves enhancing the script's Python version handling functions to robustly support pyproject.toml files, which serve as the authoritative source for package versions, thereby improving the reliability and accuracy of release version validation.

Highlights

  • Expanded Version Check Coverage: The smg-grpc-servicer package has been added to the PYTHON_PACKAGES registry in check_release_versions.sh, ensuring its version bumps are now properly checked during releases.
  • Improved Python Version Extraction: The script now correctly extracts version numbers for smg-grpc-proto by pointing to its pyproject.toml instead of __init__.py, resolving an issue where the package name was extracted instead of the version.
  • Pyproject.toml Support: The get_python_version, get_python_version_at_ref, and set_python_version functions have been updated to support reading and writing version information from pyproject.toml files, aligning with modern Python packaging standards while retaining compatibility with __init__.py.
Changelog
  • scripts/check_release_versions.sh
    • Added smg-grpc-servicer to the PYTHON_PACKAGES array for version checking.
    • Updated the smg-grpc-proto entry to reference pyproject.toml for version extraction.
    • Modified get_python_version to conditionally extract versions from pyproject.toml or __init__.py.
    • Updated get_python_version_at_ref to support version extraction from pyproject.toml at specific Git references.
    • Implemented logic in set_python_version to update versions in pyproject.toml using awk or __init__.py using sed_inplace.
Activity
  • The author provided a detailed description outlining the problem, solution, and changes, including a test plan and a checklist.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4eed9cc8-1d68-454d-a7ab-05ec13b3db0e

📥 Commits

Reviewing files that changed from the base of the PR and between 80df819 and 5933a0d.

📒 Files selected for processing (1)
  • scripts/check_release_versions.sh

📝 Walkthrough

Walkthrough

scripts/check_release_versions.sh was extended to be TOML-aware for Python packages: it reads and writes version = in pyproject.toml, preserves legacy version behavior, adds detection of non-version changes, and updates diff/phase logic to account for renames and non-version edits.

Changes

Cohort / File(s) Summary
Release script
scripts/check_release_versions.sh
Add TOML-aware Python package handling (read/write version = in pyproject.toml), add smg-grpc-servicer entry, make get_python_version, get_python_version_at_ref, and set_python_version support TOML while preserving legacy __version__ parsing, add has_non_version_changes, and update diff/phase logic to consider renames and non-version edits.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

grpc, ci, python-bindings

Suggested reviewers

  • key4ng

Poem

🐰 I nibble TOML lines with care,
I hop through versions here and there.
Proto and servicer now align,
A tiny bump, a dotted line. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the two main changes: adding smg-grpc-servicer to version check and implementing pyproject.toml support for Python packages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chang/fix-version-check-grpc

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36aeb10738

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +83 to +84
"smg-grpc-proto|crates/grpc_client/python|crates/grpc_client/python/pyproject.toml"
"smg-grpc-servicer|grpc_servicer|grpc_servicer/pyproject.toml"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Treat pyproject.toml edits as package changes

Switching version_file to pyproject.toml means Phase 1b’s change detector now filters out the package’s entire metadata file (grep -cv "$(basename "$version_file")$"), so a commit that only changes dependencies or other package metadata in pyproject.toml is counted as unchanged and skips the version-bump check. This creates false negatives for both smg-grpc-proto and smg-grpc-servicer, allowing release-impacting Python package changes to land without a required version bump.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly adds smg-grpc-servicer to the version check and switches to using pyproject.toml as the source of truth for Python package versions, which is a solid improvement. My review focuses on making the shell script's parsing logic more robust. I've identified a couple of places where the sed and awk commands could fail on edge cases, such as when version files contain comments. The suggested changes will improve the reliability of version parsing and updating.

Comment thread scripts/check_release_versions.sh
Comment thread scripts/check_release_versions.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/check_release_versions.sh (1)

241-285: 🛠️ Refactor suggestion | 🟠 Major

Scope the TOML match to the package metadata section.

The current .toml branch matches the first version = line anywhere in the file. While the existing pyproject.toml files in the repository have only one version key (under [project]), the regex pattern is fragile. If a future pyproject.toml adds a version key outside [project]/[tool.poetry] (e.g., for documentation or build configuration), get_python_version(), get_python_version_at_ref(), and set_python_version() will all match the wrong field, and the post-write verification in set_python_version() will still pass with the incorrect value.

Constrain the match to track the active TOML section and only extract/update version within [project] or [tool.poetry], or fail explicitly if the expected version key is not found.

♻️ Suggested hardening
 get_python_version() {
     local file="$1"
     if [[ "$file" == *.toml ]]; then
-        grep -m1 '^version' "$file" | sed 's/.*"\(.*\)".*/\1/'
+        awk '
+            /^\[/ { section=$0 }
+            (section == "[project]" || section == "[tool.poetry]") &&
+            /^[[:space:]]*version[[:space:]]*=[[:space:]]*".*"$/ {
+                match($0, /"([^"]+)"/, m)
+                print m[1]
+                exit
+            }
+        ' "$file"
     else
         grep '__version__' "$file" | sed 's/.*"\(.*\)".*/\1/'
     fi
 }
 
 get_python_version_at_ref() {
@@
-    if [[ "$file" == *.toml ]]; then
-        echo "$content" | grep -m1 '^version' | sed 's/.*"\(.*\)".*/\1/'
+    if [[ "$file" == *.toml ]]; then
+        echo "$content" | awk '
+            /^\[/ { section=$0 }
+            (section == "[project]" || section == "[tool.poetry]") &&
+            /^[[:space:]]*version[[:space:]]*=[[:space:]]*".*"$/ {
+                match($0, /"([^"]+)"/, m)
+                print m[1]
+                exit
+            }
+        '
     else
         echo "$content" | grep '__version__' | sed 's/.*"\(.*\)".*/\1/'
     fi
 }
 
 set_python_version() {
@@
     if [[ "$file" == *.toml ]]; then
-        awk -v new="$new_version" '
-            !done && /^version = ".*"/ { sub(/^version = ".*"/, "version = \"" new "\""); done=1 }
+        awk -v new="$new_version" '
+            /^\[/ { section=$0 }
+            !done &&
+            (section == "[project]" || section == "[tool.poetry]") &&
+            /^[[:space:]]*version[[:space:]]*=[[:space:]]*".*"$/ {
+                sub(/=.*/, "= \"" new "\"")
+                done=1
+            }
             { print }
+            END { exit done ? 0 : 1 }
         ' "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
-        if ! grep -q "^version = \"${new_version}\"" "$file"; then
+        if ! awk -v expected="$new_version" '
+            /^\[/ { section=$0 }
+            (section == "[project]" || section == "[tool.poetry]") &&
+            $0 ~ "^[[:space:]]*version[[:space:]]*=[[:space:]]*\"" expected "\"$" { found=1 }
+            END { exit found ? 0 : 1 }
+        ' "$file"; then
             echo -e "    ${RED}FAILED to update $file${NC}" >&2
             return 1
         fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/check_release_versions.sh` around lines 241 - 285, The TOML handling
in get_python_version, get_python_version_at_ref, and set_python_version
currently grabs the first version= anywhere; change each to only consider
version lines that appear inside the [project] or [tool.poetry] sections: when
reading (get_python_version and get_python_version_at_ref) parse the
file/content by tracking the current TOML section and emit the version only if
the active section is [project] or [tool.poetry], returning empty/failing if
none found; when writing (set_python_version) update the version line only if
found inside those sections (use the same section-aware scan/update) and
error/return non‑zero if no matching version key in the allowed sections was
updated so the verification check is meaningful. Ensure references to the
functions get_python_version, get_python_version_at_ref, and set_python_version
are used to locate edits.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@scripts/check_release_versions.sh`:
- Around line 241-285: The TOML handling in get_python_version,
get_python_version_at_ref, and set_python_version currently grabs the first
version= anywhere; change each to only consider version lines that appear inside
the [project] or [tool.poetry] sections: when reading (get_python_version and
get_python_version_at_ref) parse the file/content by tracking the current TOML
section and emit the version only if the active section is [project] or
[tool.poetry], returning empty/failing if none found; when writing
(set_python_version) update the version line only if found inside those sections
(use the same section-aware scan/update) and error/return non‑zero if no
matching version key in the allowed sections was updated so the verification
check is meaningful. Ensure references to the functions get_python_version,
get_python_version_at_ref, and set_python_version are used to locate edits.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 51c034a7-6c96-45ec-8674-2b30a91f22cd

📥 Commits

Reviewing files that changed from the base of the PR and between 076c8ca and 36aeb10.

📒 Files selected for processing (1)
  • scripts/check_release_versions.sh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/check_release_versions.sh`:
- Around line 283-288: The sed replacement in the non-TOML version uses a greedy
pattern "__version__ = \".*\"" which is inconsistent with other extractors and
the TOML setter; update the sed_inplace call that replaces "__version__ =
\"${new_version}\"" to use a non-greedy pattern "__version__ = \"[^\"]*\"" so it
matches only the version string (refer to the sed_inplace invocation in the
shown diff) and keep the subsequent grep check unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 50ac6022-e99e-4ef6-bacd-1fb16ad2552f

📥 Commits

Reviewing files that changed from the base of the PR and between 36aeb10 and 339cc32.

📒 Files selected for processing (1)
  • scripts/check_release_versions.sh

Comment on lines +283 to +288
else
sed_inplace "s/__version__ = \".*\"/__version__ = \"${new_version}\"/" "$file"
if ! grep -q "__version__ = \"${new_version}\"" "$file"; then
echo -e " ${RED}FAILED to update $file${NC}" >&2
return 1
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent regex: non-TOML setter still uses greedy .*.

The commit message states the fix uses non-greedy [^"]* regex, and the extraction functions (get_python_version, get_python_version_at_ref) and the TOML setter all use [^"]*. However, line 284 still uses .* which is greedy. For consistency and robustness, this should also use the non-greedy pattern.

🔧 Proposed fix
-        sed_inplace "s/__version__ = \".*\"/__version__ = \"${new_version}\"/" "$file"
+        sed_inplace "s/__version__ = \"[^\"]*\"/__version__ = \"${new_version}\"/" "$file"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else
sed_inplace "s/__version__ = \".*\"/__version__ = \"${new_version}\"/" "$file"
if ! grep -q "__version__ = \"${new_version}\"" "$file"; then
echo -e " ${RED}FAILED to update $file${NC}" >&2
return 1
fi
else
sed_inplace "s/__version__ = \"[^\"]*\"/__version__ = \"${new_version}\"/" "$file"
if ! grep -q "__version__ = \"${new_version}\"" "$file"; then
echo -e " ${RED}FAILED to update $file${NC}" >&2
return 1
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/check_release_versions.sh` around lines 283 - 288, The sed
replacement in the non-TOML version uses a greedy pattern "__version__ = \".*\""
which is inconsistent with other extractors and the TOML setter; update the
sed_inplace call that replaces "__version__ = \"${new_version}\"" to use a
non-greedy pattern "__version__ = \"[^\"]*\"" so it matches only the version
string (refer to the sed_inplace invocation in the shown diff) and keep the
subsequent grep check unchanged.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/check_release_versions.sh`:
- Around line 238-246: In get_python_version(), the non-TOML branch uses grep
without limiting to the first match; update the else branch so the grep for
'__version__' uses the same '-m1' flag as the TOML branch to ensure only the
first occurrence is returned (i.e., modify the grep call in the else branch that
extracts __version__ to include -m1).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ab4065ec-2663-4611-ba93-4da43d4c66b3

📥 Commits

Reviewing files that changed from the base of the PR and between 339cc32 and 80df819.

📒 Files selected for processing (1)
  • scripts/check_release_versions.sh

Comment thread scripts/check_release_versions.sh
CatherineSue and others added 4 commits March 9, 2026 23:41
…t.toml support

The PYTHON_PACKAGES registry was missing smg-grpc-servicer. Also, the
existing smg-grpc-proto entry pointed at __init__.py which uses
importlib.metadata (extracting the package name, not the version).

Switch both entries to read from pyproject.toml and update the
get/set_python_version helpers to handle .toml files.

Signed-off-by: Chang Su <chang.s.su@oracle.com>
Use [^"]* instead of .* inside quoted matches for sed and awk
version extraction/replacement. This prevents incorrect parsing
if a version line ever contains multiple quoted strings.

Signed-off-by: Chang Su <chang.s.su@oracle.com>
Previously, Cargo.toml and Python version files were entirely
excluded from the change count. This could hide real changes
(e.g., dependency updates) in those files. Now only version-line
changes are excluded — other modifications to manifest files
are counted as code changes that require a version bump.

Signed-off-by: Chang Su <chang.s.su@oracle.com>
The crate relocation (38ee0a5) moved crates from e.g. auth/ to
crates/auth/. This caused check_release_versions.sh to see every
file at the new path as "added", inflating diff counts and missing
feat: commits at the old path (reporting patch instead of minor).

Fix three places:

- diff_count (crate + Python loops): include both old and new paths
  in git diff, use -M for rename detection, and filter out R100
  (pure renames with no content changes)

- detect_bump_level: search commits at both old and new paths so
  feat: commits from before the move are correctly detected

- has_non_version_changes: use -M and both paths so pure renames
  of Cargo.toml/pyproject.toml don't count as content changes

Result: smg-auth correctly drops off (0 real changes), tool-parser
goes from 41 to 2 files, and several crates correctly report minor
instead of patch (llm-tokenizer, kv-index, data-connector, etc).

Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@slin1237
slin1237 force-pushed the chang/fix-version-check-grpc branch from 80df819 to 5933a0d Compare March 10, 2026 06:45
@slin1237
slin1237 merged commit cce1202 into main Mar 10, 2026
23 of 24 checks passed
@slin1237
slin1237 deleted the chang/fix-version-check-grpc branch March 10, 2026 06:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5933a0d557

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}
echo "$content" | grep '__version__' | sed 's/.*"\(.*\)".*/\1/'
if [[ "$file" == *.toml ]]; then
echo "$content" | grep -m1 '^version' | sed 's/.*"\([^"]*\)".*/\1/'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fallback to init when pyproject version is dynamic

When version_file is a TOML file, get_python_version_at_ref now parses the first ^version line directly from pyproject.toml; for older smg-grpc-proto revisions (e.g. before grpc_client/python/pyproject.toml switched to static version = "..."), that line is version = {attr = "smg_grpc_proto.__version__"}, so this returns smg_grpc_proto.__version__ instead of a semantic version. In release checks against those tags, current_version and tag_version will never match, so unchanged package versions are incorrectly treated as already bumped and required bumps can be skipped.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants