-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (161 loc) · 6.64 KB
/
ci.yml
File metadata and controls
188 lines (161 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
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 minimal installation test
run: |
# 创建一个临时目录用于测试
mkdir -p /tmp/minimal_test
cd /tmp/minimal_test
# 使用 uv 创建一个新环境并只安装项目的默认依赖
uv venv -p 3.10
# 安装项目但不包含任何可选依赖
uv pip install "$GITHUB_WORKSPACE/"
# 测试导入和版本打印
uv run python -c "import agentrun; print(f'Version: {agentrun.__version__}')"
- name: Run type check (mypy)
run: |
make mypy-check
- name: Run tests with 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