Skip to content

Instantly share code, notes, and snippets.

@ErikKalkoken
Last active January 25, 2022 13:30
Show Gist options
  • Save ErikKalkoken/4707a89b8c6784648e6565864f21f169 to your computer and use it in GitHub Desktop.
Save ErikKalkoken/4707a89b8c6784648e6565864f21f169 to your computer and use it in GitHub Desktop.
Adding pypi deploy to github

How to add PyPI deployment to GitLab

  • Create the initial project on PyPI manually via twine
  • Create an API token for PyPI with it's scope limited to the project
  • Add the API token to the GitLab project under CI/CD - Variables:
    • TWINE_USERNAME = __token__
    • TWINE_PASSWORD = The API Token. Starts with pypi-
  • Set the variables as "Masked" to prevent them from showing up in log files
  • Add a deploy section to your .gitlab.ci.yaml
  • To execute add a new tag to your commit
deploy-pypi:
 stage: deploy
 image: python:3.7-buster

 before_script:
   - pip install twine

 script:
   - python setup.py sdist
   - twine upload dist/*

 only:
   - tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment