-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,20 +30,20 @@ jobs: | |||||||||||||||||||
| with: | ||||||||||||||||||||
| python-version: '3.10' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Get latest test version and calculate next version | ||||||||||||||||||||
| - name: Get latest version from PyPI and calculate next version | ||||||||||||||||||||
| id: version | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| # 获取所有 agentrun-inner-test-v* 的 tags,找到最新版本 | ||||||||||||||||||||
| LATEST_TAG=$(git tag -l "agentrun-inner-test-v*" | sort -V | tail -n 1) | ||||||||||||||||||||
| # 从 PyPI 获取 agentrun-inner-test 的最新版本 | ||||||||||||||||||||
| PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/agentrun-inner-test/json 2>/dev/null || echo "") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if [ -z "$LATEST_TAG" ]; then | ||||||||||||||||||||
| # 如果没有找到任何 tag,从 0.0.0 开始 | ||||||||||||||||||||
| if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then | ||||||||||||||||||||
| # 如果包不存在,从 0.0.0 开始 | ||||||||||||||||||||
| CURRENT_VERSION="0.0.0" | ||||||||||||||||||||
| echo "No existing test tags found, starting from 0.0.0" | ||||||||||||||||||||
| echo "Package not found on PyPI, starting from 0.0.0" | ||||||||||||||||||||
| else | ||||||||||||||||||||
| # 从 tag 中提取版本号 | ||||||||||||||||||||
| 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'])") | ||||||||||||||||||||
|
||||||||||||||||||||
| 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
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 |
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-sflag 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: