Publish Python package with official action
- Dominant language
- C++
- Stars
- 26.5k
- Forks
- 3.7k
- PR merge metrics
- No merged PRs in 30d
Description
See [the Python packaging documentation](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#configuring-trusted-publishing), [the PyPI documentation](https://docs.pypi.org/trusted-publishers/), and [the official pypi-publish GitHub action documentation](https://github.com/pypa/gh-action-pypi-publish?tab=readme-ov-file#trusted-publishing) on trusted publishing.
Actions (click to expand)
- Configure (or use an existing) GitHub environment and add to PyPI
- In the `Publish PyPi` job of the [`Release`](https://github.com/google/flatbuffers/blob/master/.github/workflows/release.yml) CI workflow:
- add aforementioned environment (eg name `pypi`), and permissions:
```diff
+ environment:
+ name: pypi
+ url: https://pypi.org/p/flatbuffers
+ permissions:
+ id-token: write
+ contents: read
```
- in the `Upload to PyPi` step, switch to using the action:
```diff
- run: python3 -m twine upload dist/*
+ uses: pypa/gh-action-pypi-publish@release/v1`
```
- in the `Install Dependencies` step, remove `twine`:
```diff
- python3 -m pip install setuptools wheel twine
+ python3 -m pip install setuptools wheel
```
- You will be able to remove the `TWINE_TOKEN` project secret
Related: #8731
Contributor guide
Assessment
This issue has not been assessed yet.