0
点赞
收藏
分享

微信扫一扫

Python实战:GitHub Actions自动构建pypa/gh-action-pypi-publish自动发布新版本到pypi

笙烛 2022-11-05 阅读 144


每次release新包的时候,我们可以利用GitHub Actions自动构建,发布到pypi

使用pypa/gh-action-pypi-publish发布

.github/workflows/python-publish.yml

# https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml
name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build

- name: Publish package
# https://github.com/pypa/gh-action-pypi-publish
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: mouday
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true

如果发现发布失败,尝试使用第二种方式

修改后

# https://github.com/actions/starter-workflows/blob/main/ci/python-publish.yml
name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build package
run: python setup.py sdist bdist_wheel
- name: Publish package
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine check dist/*
twine upload dist/*

参考
​解决无法发布python包到Pypi​​


举报

相关推荐

0 条评论