Skip to content

Commit e2ecbfa

Browse files
committed
feat: 更新CI工作流以支持现代Python打包
- 修改wheels.yml使用python -m build替代setup.py - 添加build和twine依赖 - 实现智能版本检测(setuptools_scm) - 优化工作流步骤结构 - 更新unittest.yml使用.[test]依赖安装
1 parent 8c677c5 commit e2ecbfa

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

.github/workflows/unittest.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ jobs:
1414
python-version: [3.9]
1515
steps:
1616
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
1719
- name: Set up Python ${{ matrix.python-version }}
1820
uses: actions/setup-python@v4
1921
with:
2022
python-version: ${{ matrix.python-version }}
2123
- name: Install dependencies
2224
run: |
2325
python -m pip install --upgrade pip
24-
pip install -r requirements.txt
26+
pip install .[test]
2527
- name: Lint with flake8
2628
run: |
2729
# stop the build if there are Python syntax errors or undefined names

.github/workflows/wheels.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
inputs:
66
version:
77
description: 'Release version'
8-
required: true
8+
required: false
99

1010
jobs:
1111
build:
@@ -15,15 +15,17 @@ jobs:
1515
python-version: [3.9]
1616
steps:
1717
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
1820
- name: Set up Python ${{ matrix.python-version }}
1921
uses: actions/setup-python@v4
2022
with:
2123
python-version: ${{ matrix.python-version }}
2224
- name: Install dependencies
2325
run: |
2426
python -m pip install --upgrade pip
25-
pip install -r requirements.txt
26-
pip install wheel
27+
pip install .[test]
28+
pip install build twine
2729
2830
- name: Build Graph
2931
run: |
@@ -37,17 +39,32 @@ jobs:
3739
cp tn/*.fst graph
3840
cp itn/*.fst graph
3941
42+
- name: Get version from setuptools_scm
43+
id: scm_version
44+
run: |
45+
# Check if version is provided as input
46+
if [ -n "${{ github.event.inputs.version }}" ]; then
47+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
48+
else
49+
# Get version from setuptools_scm
50+
pip install setuptools_scm
51+
VERSION=$(python -m setuptools_scm | tail -1)
52+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
53+
fi
54+
4055
- name: Upload Graph
4156
uses: actions/upload-artifact@v3
4257
with:
43-
name: release-graph-v${{ github.event.inputs.version}}
58+
name: release-graph-v${{ steps.scm_version.outputs.VERSION }}
4459
path: graph
4560

61+
- name: Build package
62+
run: |
63+
python -m build
64+
4665
- name: Publish on pypi.org
4766
env:
4867
TWINE_USERNAME: __token__
4968
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
5069
run: |
51-
python setup.py sdist bdist_wheel --version=${{ github.event.inputs.version}}
52-
python -m pip install -U twine
53-
python -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
70+
python -m twine upload dist/*

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ build/
4242
dist/
4343
tn/*.far
4444
itn/*.far
45+
46+
# Version file(setuptools_scm generated)
47+
tn/_version.py

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ wetn = "tn.main:main"
3131
weitn = "itn.main:main"
3232

3333
[project.optional-dependencies]
34-
test = ["pytest"]
34+
test = [
35+
"pytest",
36+
"flake8"]
3537
dev = [
3638
# Development tools
3739
"flake8",

0 commit comments

Comments
 (0)