@@ -8,7 +8,9 @@ popular choice is having a workflow that's triggered by a
8
8
``push `` event.
9
9
This guide shows you how to publish a Python distribution
10
10
whenever a tagged commit is pushed.
11
- It will use the `pypa/gh-action-pypi-publish GitHub Action `_.
11
+ It will use the `pypa/gh-action-pypi-publish GitHub Action `_ for
12
+ publishing and `upload-artifact `_ and `download-artifact `_ actions
13
+ for temporarily storing and downloading the source packages.
12
14
13
15
.. attention ::
14
16
@@ -74,59 +76,47 @@ should make GitHub run this workflow:
74
76
:language: yaml
75
77
:end-before: jobs:
76
78
77
-
78
- Defining a workflow job environment
79
- ===================================
79
+ Checking out the project and building distributions
80
+ ===================================================
80
81
81
82
We will have to define two jobs to publish to PyPI
82
83
and TestPyPI respectively, and an additional job to
83
84
build the distribution packages.
84
85
85
- Now, let's add initial setup for our job that will publish to PyPI.
86
- It's a process that will execute commands that we'll define later.
87
- In this guide, we'll use the latest stable Ubuntu LTS version
88
- provided by GitHub Actions:
89
-
90
- .. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
91
- :language: yaml
92
- :start-after: on:
93
- :end-before: environment:
94
-
95
-
96
- Checking out the project and building distributions
97
- ===================================================
98
-
99
- Then, add the following under the ``build-n-publish-pypi `` section:
86
+ First, we'll define the job for building the dist packages of
87
+ your project and storing them for later use:
100
88
101
89
.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
102
90
:language: yaml
103
- :start-after: runs-on :
91
+ :start-after: jobs :
104
92
:end-before: Install pypa/build
105
93
106
94
This will download your repository into the CI runner and then
107
- install and activate the newest available Python 3 release. It
108
- also defines the package index to publish to, PyPI, and grants
109
- a permission to the action that is mandatory for trusted
110
- publishing.
111
-
112
- And now we can build dists from source. In this example, we'll
113
- use ``build `` package.
114
-
115
- .. tip ::
116
-
117
- You can use any other method for building distributions as long as
118
- it produces ready-to-upload artifacts saved into the
119
- ``dist/ `` folder. You can even use ``actions/upload-artifact `` and
120
- ``actions/download-artifact `` to tranfer files between jobs or make them
121
- accessable for download from the web CI interface.
95
+ install and activate the newest available Python 3 release.
122
96
97
+ And now we can build the dists from source and store them.
98
+ In this example, we'll use the ``build `` package.
123
99
So add this to the steps list:
124
100
125
101
.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
126
102
:language: yaml
127
103
:start-after: version: "3.x"
128
- :end-before: Actually publish to PyPI
104
+ :end-before: build-n-publish-pypi
105
+
106
+ Defining a workflow job environment
107
+ ===================================
129
108
109
+ Now, let's add initial setup for our job that will publish to PyPI.
110
+ It's a process that will execute commands that we'll define later.
111
+ In this guide, we'll use the latest stable Ubuntu LTS version
112
+ provided by GitHub Actions. This also defines the package index
113
+ to publish to, PyPI, and grants a permission to the action that
114
+ is mandatory for trusted publishing.
115
+
116
+ .. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
117
+ :language: yaml
118
+ :start-after: name: python-package-distributions
119
+ :end-before: steps:
130
120
131
121
Publishing the distribution to PyPI
132
122
===================================
@@ -135,14 +125,14 @@ Finally, add the following steps at the end:
135
125
136
126
.. literalinclude :: github-actions-ci-cd-sample/publish-to-test-pypi.yml
137
127
:language: yaml
138
- :start-after: Actually publish to PyPI
139
- :end-before: build-n-publish-testpypi
128
+ :lines: 39-47
140
129
141
130
This step uses the `pypa/gh-action-pypi-publish `_ GitHub
142
- Action: It uploads the contents of the ``dist/ `` folder
143
- into PyPI unconditionally, but only if the current commit
144
- is tagged. It is recommended you use the latest release
145
- tag; a tool like GitHub's dependabot can keep
131
+ Action: After the stored distribution package has been
132
+ downloaded by the `download-artifact `_ action, it uploads
133
+ the contents of the ``dist/ `` folder into PyPI unconditionally,
134
+ but only if the current commit is tagged. It is recommended you
135
+ use the latest release tag; a tool like GitHub's dependabot can keep
146
136
these updated regularly.
147
137
148
138
Separate workflow for publishing to TestPyPI
@@ -173,6 +163,10 @@ sure that your release pipeline remains healthy!
173
163
https://github.com/pypa/gh-action-pypi-publish
174
164
.. _`pypa/gh-action-pypi-publish GitHub Action` :
175
165
https://github.com/marketplace/actions/pypi-publish
166
+ .. _`download-artifact` :
167
+ https://github.com/actions/download-artifact
168
+ .. _`upload-artifact` :
169
+ https://github.com/actions/upload-artifact
176
170
.. _Secrets :
177
171
https://docs.github.com/en/actions/reference/encrypted-secrets
178
172
.. _trusted publishing : https://docs.pypi.org/trusted-publishers/
0 commit comments