-
Notifications
You must be signed in to change notification settings - Fork 15
Description
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
- Create an account on Pypi
- Login, and go to Account settings
- Scroll down to 'API tokens', and create a new token
- 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.
- Copy the token
- On GitHub, on the repository Deep-MI/LaPy, click on the 'Settings' tab
- Go to 'Secrets and variables'
- 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:
LaPy/.github/workflows/publish.yml
Lines 25 to 31 in 2b7a7f4
| - 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:
LaPy/.github/workflows/publish.yml
Lines 2 to 5 in 2b7a7f4
| 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