Skip to content

Commit 6c43bf4

Browse files
committed
Move build steps into separate job
1 parent b998292 commit 6c43bf4

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

source/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows.rst

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ popular choice is having a workflow that's triggered by a
88
``push`` event.
99
This guide shows you how to publish a Python distribution
1010
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.
1214

1315
.. attention::
1416

@@ -74,59 +76,47 @@ should make GitHub run this workflow:
7476
:language: yaml
7577
:end-before: jobs:
7678

77-
78-
Defining a workflow job environment
79-
===================================
79+
Checking out the project and building distributions
80+
===================================================
8081

8182
We will have to define two jobs to publish to PyPI
8283
and TestPyPI respectively, and an additional job to
8384
build the distribution packages.
8485

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:
10088

10189
.. literalinclude:: github-actions-ci-cd-sample/publish-to-test-pypi.yml
10290
:language: yaml
103-
:start-after: runs-on:
91+
:start-after: jobs:
10492
:end-before: Install pypa/build
10593

10694
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.
12296

97+
And now we can build the dists from source and store them.
98+
In this example, we'll use the ``build`` package.
12399
So add this to the steps list:
124100

125101
.. literalinclude:: github-actions-ci-cd-sample/publish-to-test-pypi.yml
126102
:language: yaml
127103
: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+
===================================
129108

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:
130120

131121
Publishing the distribution to PyPI
132122
===================================
@@ -135,14 +125,14 @@ Finally, add the following steps at the end:
135125

136126
.. literalinclude:: github-actions-ci-cd-sample/publish-to-test-pypi.yml
137127
:language: yaml
138-
:start-after: Actually publish to PyPI
139-
:end-before: build-n-publish-testpypi
128+
:lines: 39-47
140129

141130
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
146136
these updated regularly.
147137

148138
Separate workflow for publishing to TestPyPI
@@ -173,6 +163,10 @@ sure that your release pipeline remains healthy!
173163
https://github.com/pypa/gh-action-pypi-publish
174164
.. _`pypa/gh-action-pypi-publish GitHub Action`:
175165
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
176170
.. _Secrets:
177171
https://docs.github.com/en/actions/reference/encrypted-secrets
178172
.. _trusted publishing: https://docs.pypi.org/trusted-publishers/

0 commit comments

Comments
 (0)