Skip to content

Commit

Permalink
更新github action
Browse files Browse the repository at this point in the history
  • Loading branch information
dongguacute committed Dec 22, 2024
1 parent 4e4ccf8 commit 1180df1
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Python Package Publish

on:
push:
branches:
- main # 可以根据需要修改为你的主要分支名
tags:
- 'v*' # 只有当有以 v 开头的标签被推送时才会触发发布

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.8, 3.9, 3.10] # 测试多个 Python 版本

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
pytest
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

- 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

0 comments on commit 1180df1

Please sign in to comment.