Skip to content

更新workflows

更新workflows #6

name: Python Package Publish
on:
push:
branches:
- main # 根据需要修改为你的主要分支名
tags:
- 'v*' # 只有当有以 v 开头的标签被推送时才会触发发布
jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8' # 使用支持的 Python 版本,修改为合适的版本
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
pytest -v # Verbose output for better debugging
build:
runs-on: ubuntu-latest
needs: test # 仅在测试通过后执行
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # 使用不同的 Python 版本进行构建
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build the package
run: |
python setup.py sdist bdist_wheel
publish:
runs-on: ubuntu-latest
needs: build # 仅在构建成功后执行
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # 使用相同的版本进行发布
- name: Install Twine
run: |
python -m pip install --upgrade pip
pip install twine
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/* # 上传构建好的包到 PyPI