-
Notifications
You must be signed in to change notification settings - Fork 0
fix: 更新获取最新版本的逻辑,从 PyPI 获取版本信息并优化处理流程 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Change-Id: I43292d19b2bb29dbbb5efd97dabf7af3f5dc21e6 Signed-off-by: OhYee <oyohyee@oyohyee.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the version detection mechanism in the test release workflow from Git tags to PyPI API. Instead of querying local Git tags to find the latest test package version, the workflow now fetches version information directly from PyPI's JSON API for the agentrun-inner-test package.
Key Changes
- Changed version source from Git tags (
git tag -l "agentrun-inner-test-v*") to PyPI API (https://pypi.org/pypi/agentrun-inner-test/json) - Updated error handling to check for package existence on PyPI instead of missing Git tags
- Modified version extraction to parse JSON response from PyPI using Python
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [ -z "$LATEST_TAG" ]; then | ||
| # 如果没有找到任何 tag,从 0.0.0 开始 | ||
| if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for "Not Found" using grep may not be reliable for detecting PyPI errors. The PyPI API returns a 404 status code with JSON response like {"message": "Not Found"}, but curl with -s flag doesn't expose HTTP status codes. If the API returns other error formats or network issues occur, this check might not catch them.
Consider checking for valid JSON and the presence of the 'info' key instead:
if [ -z "$PYPI_RESPONSE" ] || ! echo "$PYPI_RESPONSE" | python3 -c "import sys, json; exit(0 if 'info' in json.load(sys.stdin) else 1)" 2>/dev/null; then| if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then | |
| if [ -z "$PYPI_RESPONSE" ] || ! echo "$PYPI_RESPONSE" | python3 -c "import sys, json; exit(0 if 'info' in json.load(sys.stdin) else 1)" 2>/dev/null; then |
| CURRENT_VERSION="${LATEST_TAG#agentrun-inner-test-v}" | ||
| echo "Latest test tag: $LATEST_TAG (version: $CURRENT_VERSION)" | ||
| # 从 PyPI 响应中提取最新版本 | ||
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extracted CURRENT_VERSION is not validated before being used in version parsing. If the version from PyPI has an unexpected format (e.g., "1.0.0rc1" or "1.0"), the IFS-based parsing on line 50 may produce incorrect results, leading to invalid version calculations.
Consider adding validation:
CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
# Validate version format
if ! echo "$CURRENT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Invalid version format from PyPI: $CURRENT_VERSION, starting from 0.0.0"
CURRENT_VERSION="0.0.0"
fi
echo "Latest version on PyPI: $CURRENT_VERSION"| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | |
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | |
| # Validate version format | |
| if ! echo "$CURRENT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then | |
| echo "Invalid version format from PyPI: $CURRENT_VERSION, starting from 0.0.0" | |
| CURRENT_VERSION="0.0.0" | |
| fi |
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | ||
| echo "Latest version on PyPI: $CURRENT_VERSION" |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON parsing lacks error handling. If the PyPI response doesn't contain the expected structure (e.g., missing 'info' or 'version' keys), the python command will fail and CURRENT_VERSION will be empty, leading to potential issues in version parsing.
Consider adding error handling:
CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; data = json.load(sys.stdin); print(data.get('info', {}).get('version', ''))" 2>/dev/null)
if [ -z "$CURRENT_VERSION" ]; then
echo "Failed to parse version from PyPI, starting from 0.0.0"
CURRENT_VERSION="0.0.0"
fi| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | |
| echo "Latest version on PyPI: $CURRENT_VERSION" | |
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; data = json.load(sys.stdin); print(data.get('info', {}).get('version', ''))" 2>/dev/null) | |
| if [ -z "$CURRENT_VERSION" ]; then | |
| echo "Failed to parse version from PyPI, starting from 0.0.0" | |
| CURRENT_VERSION="0.0.0" | |
| else | |
| echo "Latest version on PyPI: $CURRENT_VERSION" | |
| fi |
Change-Id: I43292d19b2bb29dbbb5efd97dabf7af3f5dc21e6
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update