From 1180df1d6e5df0c25588df02e8600f32d2d3c47a Mon Sep 17 00:00:00 2001 From: dongguacute Date: Sun, 22 Dec 2024 11:48:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0github=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/python-publish.yml | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..6b7910d --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -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