0


How to publish package to pypi in github ci

To publish a package to PyPI using GitHub CI, you can follow these steps:

  1. Create a PyPI account: Before publishing a package, you need to create an account on PyPI (https://pypi.org/) if you don’t have one already.
  2. Generate PyPI API token: Once you have a PyPI account, generate an API token. Go to your PyPI account settings and create a new API token. Make sure to save the token securely as you will need it later.
  3. Prepare your package: Ensure that your package is properly structured and contains all the necessary files. Make sure you have a setup.py file that defines your package metadata and dependencies.
  4. Configure GitHub CI workflow: In your GitHub repository, create a workflow file (e.g., .github/workflows/publish.yml) to define the CI workflow. Here’s an example workflow file:name: Publish to PyPIon:push:branches:- mainjobs:publish:runs-on: ubuntu-latest steps:-name: Checkout code uses: actions/checkout@v2 -name: Set up Python uses: actions/setup-python@v2 with:python-version: 3.x -name: Install dependencies run:| python -m pip install --upgrade pip pip install setuptools wheel twine-name: Build and publish env:TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}run:| python setup.py sdist bdist_wheel twine upload dist/*This workflow will trigger on every push to the main branch. It sets up Python, installs dependencies, builds the package, and publishes it to PyPI using twine.
  5. Add PyPI API token as a secret: In your GitHub repository, go to “Settings” > “Secrets” and create a new secret named PYPI_API_TOKEN. Paste the PyPI API token generated in step 2 as the value for this secret.
  6. Commit and push changes: Commit the workflow file and push it to your GitHub repository.
  7. Verify the workflow: Go to the “Actions” tab in your GitHub repository to see the workflow running. It should build and publish your package to PyPI.

That’s it! Your package will now be published to PyPI automatically whenever you push changes to the

main

branch. Make sure to update the workflow file and adjust it according to your package’s specific requirements.

标签: github ci/cd

本文转载自: https://blog.csdn.net/yuguo_im/article/details/135710310
版权归原作者 yuguo.im 所有, 如有侵权,请联系我们删除。

“How to publish package to pypi in github ci”的评论:

还没有评论