Skip to content

Automatic release on Pypi #18

@mscheltienne

Description

@mscheltienne

Now that the packaging is taken care of in #16 (and #17 for the typo in the line-length..), here are the steps to enable automatic releases on Pypi. Luckily, the name seems to be available: https://pypi.org/search/?q=lapy

  1. Create an account on Pypi
  2. Login, and go to Account settings
  3. Scroll down to 'API tokens', and create a new token
  4. As the project has never been uploaded to Pypi, you will not be able to select the scope 'lapy'. You will have to select 'Entire account (all projects)' giving this token the right to upload on all your projects.
  5. Copy the token
  6. On GitHub, on the repository Deep-MI/LaPy, click on the 'Settings' tab
  7. Go to 'Secrets and variables'
  8. Create a new repository secrets, named PYPI_API_TOKEN and paste the token

All done. The publication workflow is now able to build the package and upload it to Pypi:

- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*

After the first upload, you can go back to the settings on Pypi, create a new token with a scope restricted to LaPy, delete the token with full scope and replace the value of the PYPI_API_TOKEN variable on GitHub for additional safety.


When does this workflow trigger? The triggers are defined at the top:

on:
workflow_dispatch:
# release:
# types: [published]

workflow_dispatch: is a manual trigger. You can go to the 'Actions' tab of the repository click on a workflow on the left, and if it has this trigger, you will see 'Run workflow' on the right-side of the screen.

release: 
   types: [published] 

is an automatic trigger on release (at the moment, commented out), i.e. on the repository page, if you click on 'Releases' in the right-pane, then on 'Draft a new release' and publish a new release, it will automatically build and upload the repository to Pypi.

Note that the target has to be set to the branch to build and upload (and that branch must have the workflow). This is useful because usually you keep 'maintenance branches' of older release, which enable you to cherry-pick bugfixes from your active development branch and cut a new bugfix release with those fixes implemented before releasing the new minor (or major) version of your package, with the same bugfixes and many more improvements and features.


Final point, if you want to give it a shot with nothing being definitive, you can use Test PyPI instead (https://test.pypi.org/).
Final final point, once the Pypi release is done, we can create the recipe and feedstock for conda-forge which will automatically release on conda based on the release on Pypi.

I hope this was the right amount of detail, as I don't know what your knowledge is about distribution channels. Please let me know if that was too much detail and if I should shorten the explanation, or if on the contrary you still have questions.

Mathieu

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions