Skip to content

Conversation

@OhYee
Copy link
Contributor

@OhYee OhYee commented Dec 5, 2025

Change-Id: I43292d19b2bb29dbbb5efd97dabf7af3f5dc21e6

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

The specific manifestation of the bug or the associated issue.

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

Change-Id: I43292d19b2bb29dbbb5efd97dabf7af3f5dc21e6
Signed-off-by: OhYee <oyohyee@oyohyee.com>
Copilot AI review requested due to automatic review settings December 5, 2025 02:50
@OhYee OhYee merged commit 204bfad into main Dec 5, 2025
3 checks passed
@OhYee OhYee deleted the fix-add-include-usage branch December 5, 2025 02:50
Copy link
Contributor

Copilot AI left a 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
Copy link

Copilot AI Dec 5, 2025

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
Suggested change
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

Copilot uses AI. Check for mistakes.
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'])")
Copy link

Copilot AI Dec 5, 2025

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"
Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +46
CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
echo "Latest version on PyPI: $CURRENT_VERSION"
Copy link

Copilot AI Dec 5, 2025

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
Suggested change
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

Copilot uses AI. Check for mistakes.
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