1- name : Publish specbench to PyPI
1+ name : Publish to PyPI / Github
22
33on :
44 push :
55 tags :
66 - " v*.*.*"
7- workflow_dispatch : # 允许手动触发
7+ workflow_dispatch :
8+ inputs :
9+ test_only :
10+ description : ' Only publish to TestPyPI (for testing)'
11+ required : false
12+ default : false
13+ type : boolean
814
915jobs :
10- publish :
16+ build-and- publish-pypi :
1117 runs-on : ubuntu-latest
18+ permissions :
19+ contents : write
1220
1321 steps :
1422 - name : Checkout repository
1523 uses : actions/checkout@v4
1624
17- - name : Install uv
18- uses : astral-sh /setup-uv @v4
25+ - name : Set up Python
26+ uses : actions /setup-python @v4
1927 with :
20- version : " latest "
28+ python- version : ' 3.10 '
2129
22- - name : Set up Python
23- run : uv python install 3.10
30+ - name : Install uv
31+ run : pip install uv
32+
33+ - name : Setup virtual environment
34+ run : uv venv .venv --python=3.10
2435
2536 - name : Extract version from tag
2637 run : |
@@ -29,35 +40,81 @@ jobs:
2940
3041 - name : Update version in pyproject.toml
3142 run : |
32- # 使用 sed 更新版本号
3343 sed -i "s/version = \".*\"/version = \"$VERSION\"/" pyproject.toml
3444 echo "Updated version to $VERSION"
35-
36- - name : Verify project structure
37- run : |
38- echo "Project structure:"
39- ls -la
40- echo "Specbench package:"
41- ls -la specbench/
45+ grep "version =" pyproject.toml
4246
4347 - name : Build package
48+ run : uv build
49+
50+ # 🎯 测试发布到 TestPyPI(手动触发或测试时)
51+ - name : Publish to TestPyPI
52+ if : github.event_name == 'workflow_dispatch' && inputs.test_only == true
53+ env :
54+ UV_PUBLISH_TOKEN : ${{ secrets.TEST_PYPI_API_KEY }}
4455 run : |
45- uv build
46- echo "Built packages:"
47- ls -la dist/
56+ echo "🧪 Publishing to TestPyPI for testing..."
57+ uv publish --publish-url https://test.pypi.org/legacy/ --verbose
4858
59+ # 🚀 正式发布到 PyPI(标签触发)
4960 - name : Publish to PyPI
61+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
62+ env :
63+ UV_PUBLISH_TOKEN : ${{ secrets.PYPI_API_KEY }}
64+ run : |
65+ echo "🚀 Publishing to PyPI..."
66+ uv publish --publish-url https://upload.pypi.org/legacy/ --verbose
67+
68+ # 📦 备用方案:使用 twine
69+ - name : Publish with twine (fallback)
70+ if : failure() # 如果上面的步骤失败
5071 env :
51- UV_PUBLISH_TOKEN : ${{ secrets.PYPI_TOKEN }}
72+ TWINE_USERNAME : __token__
73+ TWINE_PASSWORD : ${{ github.event_name == 'push' && secrets.PYPI_API_KEY || secrets.TEST_PYPI_API_KEY }}
74+ TWINE_REPOSITORY_URL : ${{ github.event_name == 'push' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/' }}
75+ run : |
76+ source .venv/bin/activate
77+ uv pip install twine
78+ twine upload dist/* --verbose
79+
80+ - name : Upload built artifacts
81+ uses : actions/upload-artifact@v4
82+ with :
83+ name : dist
84+ path : dist
85+
86+ create-release :
87+ name : Create GitHub Release
88+ runs-on : ubuntu-latest
89+ needs : build-and-publish-pypi
90+ # 只有正式发布时才创建 Release
91+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
92+ permissions :
93+ contents : write
94+
95+ steps :
96+ - name : Checkout code
97+ uses : actions/checkout@v4
98+
99+ - name : Download built artifacts
100+ uses : actions/download-artifact@v4
101+ with :
102+ name : dist
103+ path : dist
104+
105+ - name : Check tag for pre-release
106+ id : prerelease_check
52107 run : |
53- uv publish
108+ if [[ "${{ github.ref_name }}" == *"alpha"* ]] || [[ "${{ github.ref_name }}" == *"beta"* ]] || [[ "${{ github.ref_name }}" == *"rc"* ]]; then
109+ echo "prerelease=true" >> $GITHUB_OUTPUT
110+ else
111+ echo "prerelease=false" >> $GITHUB_OUTPUT
112+ fi
54113
55- - name : Create GitHub Release
114+ - name : Release to GitHub
56115 uses : softprops/action-gh-release@v2
57- if : startsWith(github.ref, 'refs/tags/')
58116 with :
59- files : |
60- dist/*.whl
61- dist/*.tar.gz
62117 generate_release_notes : true
63- name : " Release ${{ env.VERSION }}"
118+ draft : false
119+ prerelease : ${{ steps.prerelease_check.outputs.prerelease }}
120+ files : dist/*
0 commit comments