@@ -24,19 +24,23 @@ This guide relies on PyPI's `trusted publishing`_ implementation to connect
2424to `GitHub Actions CI/CD `_. This is recommended for security reasons, since
2525the generated tokens are created for each of your projects
2626individually and expire automatically. Otherwise you'll need to generate an
27- `API token `_ or provide a username/password combination for both PyPI and
28- TestPyPI.
27+ `API token `_ for both PyPI and TestPyPI. In case of publishing to third-party
28+ indexes like :doc: `devpi <devpi:index >`, you will need to provide a
29+ username/password combination.
2930
3031Since this guide will demonstrate uploading to both
3132PyPI and TestPyPI, we'll need two trusted publishers configured.
32- The following steps will lead you through creating the "pending" publishers.
33+ The following steps will lead you through creating the "pending" publishers
34+ for your new project. However it is also possible to add `trusted publishing `_
35+ to any pre-existing project, if you are its owner.
3336
3437Let's begin! 🚀
3538
36- 1. Go to https://pypi.org/manage/account/publishing/
39+ 1. Go to https://pypi.org/manage/account/publishing/.
37402. Fill in the name you wish to publish your new project under,
38- your repository data and the name of the release workflow file
39- under the ``.github/ `` folder, see :ref: `workflow-definition `.
41+ your GitHub username and repository name and
42+ the name of the release workflow file under
43+ the ``.github/ `` folder, see :ref: `workflow-definition `.
4044 Finally add the name of the GitHub Actions environment
4145 running under your repository.
4246 Register the trusted publisher.
@@ -74,29 +78,35 @@ should make GitHub run this workflow:
7478Defining a workflow job environment
7579===================================
7680
77- Now, let's add initial setup for our job. It's a process that
78- will execute commands that we'll define later.
81+ We will have to define two jobs to publish to PyPI
82+ and TestPyPI respectively.
83+
84+ Now, let's add initial setup for our job that will publish to PyPI.
85+ It's a process that will execute commands that we'll define later.
7986In this guide, we'll use the latest stable Ubuntu LTS version
8087provided by GitHub Actions:
8188
8289.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
8390 :language: yaml
8491 :start-after: on:
85- :end-before: steps :
92+ :end-before: environment :
8693
8794
8895Checking out the project and building distributions
8996===================================================
9097
91- Then, add the following under the ``build-n-publish `` section:
98+ Then, add the following under the ``build-n-publish-pypi `` section:
9299
93100.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
94101 :language: yaml
95102 :start-after: runs-on:
96103 :end-before: Install pypa/build
97104
98105This will download your repository into the CI runner and then
99- install and activate the newest available Python 3 release.
106+ install and activate the newest available Python 3 release. It
107+ also defines the package index to publish to, PyPI, and grants
108+ a permission to the action that is mandatory for trusted
109+ publishing.
100110
101111And now we can build dists from source. In this example, we'll
102112use ``build `` package.
@@ -114,25 +124,36 @@ So add this to the steps list:
114124.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
115125 :language: yaml
116126 :start-after: version: "3.x"
117- :end-before: Actually publish to PyPI/TestPyPI
127+ :end-before: Actually publish to PyPI
118128
119129
120- Publishing the distribution to PyPI and TestPyPI
121- ================================================
130+ Publishing the distribution to PyPI
131+ ===================================
122132
123133Finally, add the following steps at the end:
124134
125135.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
126136 :language: yaml
127- :start-after: Actually publish to PyPI/TestPyPI
128-
129- These two steps use the `pypa/gh-action-pypi-publish `_ GitHub
130- Action: the first one uploads contents of the ``dist/ `` folder
131- into TestPyPI unconditionally and the second does that to
132- PyPI, but only if the current commit is tagged. It is recommended
133- you use the latest release tag; a tool like GitHub's dependabot can keep
137+ :start-after: Actually publish to PyPI
138+ :end-before: build-n-publish-testpypi
139+
140+ This step uses the `pypa/gh-action-pypi-publish `_ GitHub
141+ Action: It uploads the contents of the ``dist/ `` folder
142+ into PyPI unconditionally, but only if the current commit
143+ is tagged. It is recommended you use the latest release
144+ tag; a tool like GitHub's dependabot can keep
134145these updated regularly.
135146
147+ Separate workflow for publishing to TestPyPI
148+ ============================================
149+
150+ Now, repeat these steps and create another job for
151+ publishing to the TestPyPI package index under the ``jobs ``
152+ section:
153+
154+ .. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
155+ :language: yaml
156+ :start-after: uses: pypa/gh-action-pypi-publish@release/v1
136157
137158That's all, folks!
138159==================
0 commit comments