Skip to content

Commit 8b1760e

Browse files
committed
chore(action): github actions for publish to pypi / github
1 parent f8f2c5c commit 8b1760e

7 files changed

Lines changed: 93 additions & 64 deletions

File tree

.github/workflows/docs-deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: Deploy VitePress Docs Site to Pages
33
on:
44
push:
55
branches: [main]
6+
paths:
7+
- 'docs/**'
8+
- '.github/workflows/docs-deploy.yml'
69
workflow_dispatch:
710

811
permissions:
Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
name: Publish specbench to PyPI
1+
name: Publish to PyPI / Github
22

33
on:
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

915
jobs:
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/*

.github/workflows/test-publish.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/test-when-pr.yml

Whitespace-only changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Virtual environments & Python cache
55
*.venv/
66
*__pycache__/
7+
.ruff_cache/
78

89
# System files
910
.DS_Store

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
hooks:
66
- id: ruff
77
# auto fix
8-
args: [--fix]
8+
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
99
exclude: ^docs
1010
- id: ruff-format
1111
exclude: ^docs

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ version = "0.0.1"
88
description = "化学谱学大模型 Benchmark 引擎"
99
readme = "README.md"
1010
requires-python = ">=3.10"
11-
authors = [{ name = "Zhuo Yang, Tianfan Fu" }]
11+
authors = [
12+
{ name = "Zhuo Yang", email = "yzachary1551@gmail.com" },
13+
{ name = "Tianfan Fu", email = "futianfan@gmail.com" },
14+
]
1215
keywords = ["benchmark", "chemistry", "spectroscopy", "evaluation"]
1316

1417
dependencies = ["dotenv>=0.9.9", "openai>=1.93.0"]

0 commit comments

Comments
 (0)