@@ -9,7 +9,7 @@ popular choice is having a workflow that's triggered by a
99This guide shows you how to publish a Python distribution
1010whenever a tagged commit is pushed.
1111It will use the `pypa/gh-action-pypi-publish GitHub Action `_ for
12- publishing. It also uses GitHub's `upload-artifact `_ and `download-artifact `_ actions
12+ publishing. It also uses GitHub's `upload-artifact `_ and `download-artifact `_ actions
1313for temporarily storing and downloading the source packages.
1414
1515.. attention ::
@@ -23,15 +23,15 @@ Configuring trusted publishing
2323==============================
2424
2525This guide relies on PyPI's `trusted publishing `_ implementation to connect
26- to `GitHub Actions CI/CD `_. This is recommended for security reasons, since
26+ to `GitHub Actions CI/CD `_. This is recommended for security reasons, since
2727the generated tokens are created for each of your projects
2828individually and expire automatically. Otherwise, you'll need to generate an
2929`API token `_ for both PyPI and TestPyPI. In case of publishing to third-party
3030indexes like :doc: `devpi <devpi:index >`, you may need to provide a
3131username/password combination.
3232
3333Since this guide will demonstrate uploading to both
34- PyPI and TestPyPI, we'll need two trusted publishers configured.
34+ PyPI and TestPyPI, we'll need two trusted publishers configured.
3535The following steps will lead you through creating the "pending" publishers
3636for your new :term: `PyPI project <Project> `.
3737However it is also possible to add `trusted publishing `_ to any
@@ -52,17 +52,17 @@ Let's begin! 🚀
52522. Fill in the name you wish to publish your new
5353 :term: `PyPI project <Project> ` under
5454 (the ``name `` value in your ``setup.cfg `` or ``pyproject.toml ``),
55- your GitHub username and repository name and
56- the name of the release workflow file under
55+ the GitHub repository owner's name (org or user)
56+ and repository name and the name of the release workflow file under
5757 the ``.github/ `` folder, see :ref: `workflow-definition `.
5858 Finally add the name of the GitHub Actions environment
5959 (``pypi ``) we're going set up under your repository.
6060 Register the trusted publisher.
61613. Now, go to https://test.pypi.org/manage/account/publishing/ and repeat
6262 the second step, but now enter ``testpypi `` as the name of the
6363 GitHub Actions environment.
64- 4. Your "pending" publishers are now ready for their first use and will
65- create your projects automatically once you use them
64+ 4. Your "pending" publishers are now ready for their first use and will
65+ create your projects automatically once you use them
6666 for the first time.
6767
6868 .. note ::
@@ -95,23 +95,19 @@ should make GitHub run this workflow:
9595 :language: yaml
9696 :end-before: jobs:
9797
98- This will also ensure that the release workflow is only triggered
99- if the current commit is tagged. It is recommended you use the
100- latest release tag.
101-
10298Checking out the project and building distributions
10399===================================================
104100
105- We will have to define two jobs to publish to PyPI
106- and TestPyPI respectively, and an additional job to
101+ We will have to define two jobs to publish to PyPI
102+ and TestPyPI respectively, and an additional job to
107103build the distribution packages.
108104
109- First, we'll define the job for building the dist packages of
105+ First, we'll define the job for building the dist packages of
110106your project and storing them for later use:
111107
112108.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
113109 :language: yaml
114- :start-after : jobs:
110+ :start-at : jobs:
115111 :end-before: Install pypa/build
116112
117113This will download your repository into the CI runner and then
@@ -123,7 +119,7 @@ So add this to the steps list:
123119
124120.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
125121 :language: yaml
126- :start-after: version: "3.x"
122+ :start-at: Install pypa/build
127123 :end-before: publish-to-pypi
128124
129125Defining a workflow job environment
@@ -135,14 +131,18 @@ In this guide, we'll use the latest stable Ubuntu LTS version
135131provided by GitHub Actions. This also defines a GitHub Environment
136132for the job to run in its context and a URL to be displayed in GitHub's
137133UI nicely. Additionally, it allows aqcuiring an OpenID Connect token
138- which is mandatory that the ``pypi-publish `` actions needs to
139- implement secretless trusted publishing to PyPI.
134+ that the ``pypi-publish `` actions needs to implement secretless
135+ trusted publishing to PyPI.
140136
141137.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
142138 :language: yaml
143139 :start-after: path: dist/
144140 :end-before: steps:
145141
142+ This will also ensure that the PyPI publishing workflow is only triggered
143+ if the current commit is tagged. It is recommended you use the
144+ latest release tag.
145+
146146Publishing the distribution to PyPI
147147===================================
148148
@@ -151,14 +151,24 @@ Finally, add the following steps at the end:
151151.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
152152 :language: yaml
153153 :start-after: id-token: write
154- :end-before: publish-to-testpypi :
154+ :end-before: github-release :
155155
156156This step uses the `pypa/gh-action-pypi-publish `_ GitHub
157- Action: after the stored distribution package has been
158- downloaded by the `download-artifact `_ action, it uploads
157+ Action: after the stored distribution package has been
158+ downloaded by the `download-artifact `_ action, it uploads
159159the contents of the ``dist/ `` folder into PyPI unconditionally.
160- This job also signs the artifacts with the `sigstore/gh-action-sigstore-python `_
161- GitHub Action publishing them to PyPI.
160+
161+ Signing the distribution packages
162+ =================================
163+
164+ This additional job signs the distribution packages with the
165+ `sigstore/gh-action-sigstore-python GitHub Action `_ and then uploads
166+ them to GitHub Release.
167+
168+ .. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
169+ :language: yaml
170+ :start-at: github-release:
171+ :end-before: publish-to-testpypi
162172
163173Separate workflow for publishing to TestPyPI
164174============================================
@@ -169,8 +179,15 @@ section:
169179
170180.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
171181 :language: yaml
172- :start-after: ./dist/*.whl
182+ :start-at: publish-to-testpypi
183+
184+ The whole CD workflow
185+ =====================
186+
187+ .. collapse :: Load file
173188
189+ .. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
190+ :language: yaml
174191
175192That's all, folks!
176193==================
@@ -193,7 +210,7 @@ sure that your release pipeline remains healthy!
193210 https://github.com/actions/download-artifact
194211.. _`upload-artifact` :
195212 https://github.com/actions/upload-artifact
196- .. _`sigstore/gh-action-sigstore-python` :
213+ .. _`sigstore/gh-action-sigstore-python GitHub Action ` :
197214 https://github.com/marketplace/actions/gh-action-sigstore-python
198215.. _Secrets :
199216 https://docs.github.com/en/actions/reference/encrypted-secrets
0 commit comments