Update scripts/check_coverage.py #13
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| # 仅在 push 时触发测试 | |
| push: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.10'] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取完整历史用于增量覆盖率检查 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| make setup PYTHON_VERSION=${{ matrix.python-version }} | |
| - name: Run type check (mypy) | |
| run: | | |
| make mypy-check | |
| - name: Run unit tests | |
| run: | | |
| make test-unit | |
| - name: Run coverage | |
| run: | | |
| make coverage | |
| # 检测文件更改并决定是否构建测试包 | |
| - name: Check for changes in agentrun directory | |
| id: changes | |
| run: | | |
| echo "Checking if agentrun directory has changes..." | |
| # 获取最近两次提交之间的差异;如果没有父提交,则将所有跟踪文件视为已更改 | |
| if git rev-parse HEAD^ >/dev/null 2>&1; then | |
| git diff --name-only HEAD^ HEAD > changed_files.txt | |
| else | |
| echo "No parent commit; treating all tracked files as changed." | |
| git ls-files > changed_files.txt | |
| fi | |
| echo "Changed files:" | |
| cat changed_files.txt || echo "No changed files detected" | |
| # 检查是否有任何以 agentrun/ 开头的文件 | |
| if grep -q "^agentrun/" changed_files.txt 2>/dev/null; then | |
| echo "agentrun directory has changes" | |
| echo "agentrun_changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "agentrun directory has no changes" | |
| echo "agentrun_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| # 测试通过后自动构建测试包(仅在 agentrun 目录有变化时触发) | |
| - name: Get latest version from PyPI and calculate next version | |
| id: version | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| # 从 PyPI 获取 agentrun-inner-test 的最新版本 | |
| PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/agentrun-inner-test/json 2>/dev/null || echo "") | |
| if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then | |
| # 如果包不存在,从 0.0.0 开始 | |
| CURRENT_VERSION="0.0.0" | |
| echo "Package not found on PyPI, starting from 0.0.0" | |
| else | |
| # 从 PyPI 响应中提取最新版本 | |
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | |
| echo "Latest version on PyPI: $CURRENT_VERSION" | |
| fi | |
| # 解析版本号 | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
| # 默认为 patch | |
| BUMP_TYPE="patch" | |
| case "$BUMP_TYPE" in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| NEW_TAG="agentrun-inner-test-v${NEW_VERSION}" | |
| echo "VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "TAG=${NEW_TAG}" >> $GITHUB_OUTPUT | |
| echo "New version: ${NEW_VERSION}" | |
| echo "New tag: ${NEW_TAG}" | |
| - name: Update package name and version in pyproject.toml | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| VERSION="${{ steps.version.outputs.VERSION }}" | |
| # 修改包名为 agentrun-inner-test | |
| sed -i 's/name = "agentrun-sdk"/name = "agentrun-inner-test"/' pyproject.toml | |
| # 修改版本号 | |
| sed -i 's/version = "[^"]*"/version = "'${VERSION}'"/' pyproject.toml | |
| echo "Updated pyproject.toml:" | |
| head -10 pyproject.toml | |
| - name: Update __version__ in __init__.py | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| VERSION="${{ steps.version.outputs.VERSION }}" | |
| if grep -q "__version__" agentrun/__init__.py; then | |
| sed -i 's/__version__ = "[^"]*"/__version__ = "'${VERSION}'"/' agentrun/__init__.py | |
| else | |
| sed -i '1a __version__ = "'${VERSION}'"' agentrun/__init__.py | |
| fi | |
| echo "Updated __init__.py version to ${VERSION}" | |
| grep "__version__" agentrun/__init__.py | |
| - name: Build package | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| python -m build | |
| echo "Package built successfully" | |
| ls -la dist/ | |
| - name: Verify package | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| python -m twine check dist/* | |
| echo "Package verification completed" | |
| - name: Publish to PyPI | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| verify-metadata: false | |
| - name: Create and push tag | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| TAG="${{ steps.version.outputs.TAG }}" | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git tag -a "$TAG" -m "Release test package version ${{ steps.version.outputs.VERSION }}" | |
| git push origin "$TAG" | |
| echo "Created and pushed tag: $TAG" | |
| - name: Summary | |
| if: steps.changes.outputs.agentrun_changed == 'true' | |
| run: | | |
| echo "## 🎉 Test Package Released!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Package Name:** agentrun-inner-test" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version:** ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Tag:** ${{ steps.version.outputs.TAG }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Install with: \`pip install agentrun-inner-test==${{ steps.version.outputs.VERSION }}\`" >> $GITHUB_STEP_SUMMARY | |