2222 with :
2323 python-version : ${{ matrix.python-version }}
2424
25- - name : Install uv
26- run : |
27- pip install uv
28- echo "✅ uv installed: $(uv --version)"
29-
3025 - name : Install dependencies
3126 run : |
32- uv sync \
33- --python ${{ matrix.python-version }} \
34- --dev \
35- --all-extras
27+ make setup PYTHON_VERSION=${{ matrix.python-version }}
3628
3729 - name : Run type check (mypy)
3830 run : |
@@ -46,12 +38,135 @@ jobs:
4638 run : |
4739 uv run python scripts/check_coverage.py --incremental
4840
49- # 测试通过后自动构建测试包(仅在 push 到 main/master/develop 分支时触发)
50- build-test-package :
51- needs : test
52- if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
53- uses : ./.github/workflows/release-test.yml
54- secrets : inherit
55- with :
56- version_bump : ' patch'
41+ # 检测文件更改并决定是否构建测试包
42+ - name : Check for changes in agentrun directory
43+ id : changes
44+ run : |
45+ echo "Checking if agentrun directory has changes..."
46+ # 获取最近两次提交之间的差异
47+ git diff --name-only HEAD^ HEAD > changed_files.txt || echo "Cannot get diff, checking all files" > changed_files.txt
48+ echo "Changed files:"
49+ cat changed_files.txt || echo "No changed files detected"
50+
51+ # 检查是否有任何以 agentrun/ 开头的文件
52+ if grep -q "^agentrun/" changed_files.txt 2>/dev/null; then
53+ echo "agentrun directory has changes"
54+ echo "agentrun_changed=true" >> $GITHUB_OUTPUT
55+ else
56+ echo "agentrun directory has no changes"
57+ echo "agentrun_changed=false" >> $GITHUB_OUTPUT
58+ fi
59+
60+ # 测试通过后自动构建测试包(仅在 agentrun 目录有变化时触发)
61+ - name : Get latest version from PyPI and calculate next version
62+ id : version
63+ if : steps.changes.outputs.agentrun_changed == 'true'
64+ run : |
65+ # 从 PyPI 获取 agentrun-inner-test 的最新版本
66+ PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/agentrun-inner-test/json 2>/dev/null || echo "")
67+
68+ if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then
69+ # 如果包不存在,从 0.0.0 开始
70+ CURRENT_VERSION="0.0.0"
71+ echo "Package not found on PyPI, starting from 0.0.0"
72+ else
73+ # 从 PyPI 响应中提取最新版本
74+ CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
75+ echo "Latest version on PyPI: $CURRENT_VERSION"
76+ fi
77+
78+ # 解析版本号
79+ IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
80+
81+ # 默认为 patch
82+ BUMP_TYPE="patch"
83+ case "$BUMP_TYPE" in
84+ major)
85+ MAJOR=$((MAJOR + 1))
86+ MINOR=0
87+ PATCH=0
88+ ;;
89+ minor)
90+ MINOR=$((MINOR + 1))
91+ PATCH=0
92+ ;;
93+ patch)
94+ PATCH=$((PATCH + 1))
95+ ;;
96+ esac
97+
98+ NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
99+ NEW_TAG="agentrun-inner-test-v${NEW_VERSION}"
100+
101+ echo "VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
102+ echo "TAG=${NEW_TAG}" >> $GITHUB_OUTPUT
103+ echo "New version: ${NEW_VERSION}"
104+ echo "New tag: ${NEW_TAG}"
105+
106+ - name : Update package name and version in pyproject.toml
107+ if : steps.changes.outputs.agentrun_changed == 'true'
108+ run : |
109+ VERSION="${{ steps.version.outputs.VERSION }}"
110+ # 修改包名为 agentrun-inner-test
111+ sed -i 's/name = "agentrun-sdk"/name = "agentrun-inner-test"/' pyproject.toml
112+ # 修改版本号
113+ sed -i 's/version = "[^"]*"/version = "'${VERSION}'"/' pyproject.toml
114+ echo "Updated pyproject.toml:"
115+ head -10 pyproject.toml
116+
117+ - name : Update __version__ in __init__.py
118+ if : steps.changes.outputs.agentrun_changed == 'true'
119+ run : |
120+ VERSION="${{ steps.version.outputs.VERSION }}"
121+ if grep -q "__version__" agentrun/__init__.py; then
122+ sed -i 's/__version__ = "[^"]*"/__version__ = "'${VERSION}'"/' agentrun/__init__.py
123+ else
124+ sed -i '1a __version__ = "'${VERSION}'"' agentrun/__init__.py
125+ fi
126+ echo "Updated __init__.py version to ${VERSION}"
127+ grep "__version__" agentrun/__init__.py
128+
129+ - name : Build package
130+ if : steps.changes.outputs.agentrun_changed == 'true'
131+ run : |
132+ python -m pip install --upgrade pip
133+ pip install build twine
134+ python -m build
135+ echo "Package built successfully"
136+ ls -la dist/
137+
138+ - name : Verify package
139+ if : steps.changes.outputs.agentrun_changed == 'true'
140+ run : |
141+ python -m twine check dist/*
142+ echo "Package verification completed"
143+
144+ - name : Publish to PyPI
145+ if : steps.changes.outputs.agentrun_changed == 'true'
146+ uses : pypa/gh-action-pypi-publish@release/v1
147+ with :
148+ password : ${{ secrets.PYPI_API_TOKEN }}
149+ verify-metadata : false
150+
151+ - name : Create and push tag
152+ if : steps.changes.outputs.agentrun_changed == 'true'
153+ run : |
154+ TAG="${{ steps.version.outputs.TAG }}"
155+ git config --local user.email "action@github.com"
156+ git config --local user.name "GitHub Action"
157+ git tag -a "$TAG" -m "Release test package version ${{ steps.version.outputs.VERSION }}"
158+ git push origin "$TAG"
159+ echo "Created and pushed tag: $TAG"
160+
161+ - name : Summary
162+ if : steps.changes.outputs.agentrun_changed == 'true'
163+ run : |
164+ echo "## 🎉 Test Package Released!" >> $GITHUB_STEP_SUMMARY
165+ echo "" >> $GITHUB_STEP_SUMMARY
166+ echo "- **Package Name:** agentrun-inner-test" >> $GITHUB_STEP_SUMMARY
167+ echo "- **Version:** ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
168+ echo "- **Tag:** ${{ steps.version.outputs.TAG }}" >> $GITHUB_STEP_SUMMARY
169+ echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
170+ echo "" >> $GITHUB_STEP_SUMMARY
171+ echo "Install with: \`pip install agentrun-inner-test==${{ steps.version.outputs.VERSION }}\`" >> $GITHUB_STEP_SUMMARY
57172
0 commit comments