Skip to content

Conversation

@mjpieters
Copy link
Collaborator

@mjpieters mjpieters commented May 16, 2023

This ensures that any releases are fully tested before publication.

The workflow first builds the distribution files (sdist, wheel) before using a deployment environment to publish these to PyPI, using the GitHub actions OpenID support to authenticate with PyPI.

Note that this requires that a trusted publisher has been configured for the project for this to work.

@mjpieters
Copy link
Collaborator Author

mjpieters commented May 16, 2023

@long2ice: for this one, I need your help. Could you please configure a trusted publisher for the project? Initially on https://test.pypi.org to verify the workflow is doing what it needs to do, then on PyPI itself. The trusted publisher configuration can then be used by the PyPA publisher action to push the new distributions to PyPI without the need to store PyPI token in a secret.

The linked page gives you detailed instructions; all you need is these parameters:

Field Value
Owner long2ice
Repository name fastapi-cache
Workflow name ci-cd.yml
Environment name pypi

Once the trusted publisher has been configured we can re-run the action steps here and see the package get pushed to test.pypi.org, and once that succeeds I'll remove that step to only leave the PyPI push step, which only fires when an annotated tag has been committed and pushed.

In future, this workflow could also gain a github release step, but that's far less important for Python packages, and I'd like to have a changelog in place first so there is some text to push for a release.

@long2ice
Copy link
Owner

Good job! Done for that.

@mjpieters
Copy link
Collaborator Author

@long2ice: Did you set up the publisher on test.pypi.org or only on the main pypi.org site?

The workflow still failed with the same error, unfortunately, when it tried to publish to test.pypi.

@long2ice
Copy link
Owner

Oh I loss that, but still failed

@mjpieters
Copy link
Collaborator Author

mjpieters commented May 17, 2023 via email

@mjpieters
Copy link
Collaborator Author

mjpieters commented May 17, 2023

@long2ice: successful deployment! See https://test.pypi.org/project/fastapi-cache2/0.2.1/.

I'll update the PR to only run the publish job when there was a push to a version tag, and merge.

Thanks again for handling the PyPI setup!

This ensures that any releases are fully tested before publication.

The workflow first builds the distribution files (sdist, wheel) before
using a deployment environment to publish these to PyPI, using the
GitHub actions OpenID support to authenticate with PyPI.
@mjpieters
Copy link
Collaborator Author

@long2ice: last but not least, you may want to review the options to protect the deployment environment.

It is not uncommon to require a manual approval by a reviewer before deploying, so you can review if the distributions created look sane before allowing the upload to happen, and to limit what branches can deploy (I'd set it to main here).

@mjpieters mjpieters merged commit 826e785 into main May 17, 2023
@mjpieters mjpieters deleted the release_wf branch May 17, 2023 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants