blaise-blog/releasing: gitlab to pypi

This post contains my notes for how I release a Python project from GitLab to PyPI. I love hosting projects on GitLab since I can use the built-in runners to release automatically.

table of contents

first release

The very first release is necessarily a very manual process. Once the project is on PyPI, subsequent releases can be automated.

test packaging

First, you want to make sure that your source code is correct. There are a lot of little regretable mistakes to be made.

tag on GitLab

If you already have gitlab-ci setup to release on tag, it will try and surely fail. That's OK for this initail release. You can cancel it, if you think to.

release on PyPI

Now we actually release to PyPI.

Horray! Don't forget to log into PyPI and make other project maintainers into "owners".


In this section we will set up gitlab-ci to automatically release everytime a new tag is made.

add release to ci

In .gitlab-ci.yml:

  stage: deploy
    - python sdist bdist_wheel
    - twine upload dist/*
      - dist/*
    - tags

protect tags

Within the GitLab repository, we must mark tags that we intend to release as protected. This is intended as a safety feature so that only maintainers are able to release. On GitLab:

add variables

PyPI allows uploads via tokens. This is how we will authenticate and let PyPI know that we are who we say we are. First, we need to generate the token. On PyPI:

On GitLab:

subsequent releases

On subsequent releases gitlab should release for you on tag.

built 2020-05-24 16:35:57                                      CC0: no copyright