Skip to content

Commit 1851d9f

Browse files
chryslewebknjaz
andcommitted
Apply suggestions from code review
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
1 parent 25ef745 commit 1851d9f

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

source/guides/github-actions-ci-cd-sample/publish-to-test-pypi.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
22

33
on: push
44

5-
# Only trigger this for tag changes.
6-
if: startsWith(github.ref, 'refs/tags/')
7-
85
jobs:
96
build:
107
name: Build the source package
118
runs-on: ubuntu-latest
9+
1210
steps:
1311
- uses: actions/checkout@v3
1412
- name: Set up Python
@@ -22,15 +20,19 @@ jobs:
2220
build
2321
--user
2422
- name: Build a binary wheel and a source tarball
25-
run: >-
26-
python3 -m
27-
build
23+
run: python3 -m build
2824
- name: Store the distribution packages
2925
uses: actions/upload-artifact@v3
3026
with:
3127
name: python-package-distributions
28+
path: dist/
29+
3230
publish-to-pypi:
33-
name: Build and publish Python 🐍 distributions 📦 to PyPI
31+
name: >-
32+
Publish Python 🐍 distributions 📦 to PyPI
33+
and sign them with Sigstore
34+
needs:
35+
- build
3436
runs-on: ubuntu-latest
3537
environment:
3638
name: pypi
@@ -46,8 +48,18 @@ jobs:
4648
path: dist/
4749
- name: Publish distribution 📦 to PyPI
4850
uses: pypa/gh-action-pypi-publish@release/v1
51+
- name: Sign the dists with Sigstore
52+
uses: sigstore/[email protected]
53+
with:
54+
inputs: >-
55+
./dist/*.tar.gz
56+
./dist/*.whl
57+
4958
publish-to-testpypi:
5059
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
60+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
61+
needs:
62+
- build
5163
runs-on: ubuntu-latest
5264
environment:
5365
name: testpypi
@@ -61,7 +73,7 @@ jobs:
6173
with:
6274
name: python-package-distributions
6375
path: dist/
64-
- name: Publish distribution 📦 to Test PyPI
76+
- name: Publish distribution 📦 to TestPyPI
6577
uses: pypa/gh-action-pypi-publish@release/v1
6678
with:
6779
repository-url: https://test.pypi.org/legacy/

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Configuring trusted publishing
2525
This guide relies on PyPI's `trusted publishing`_ implementation to connect
2626
to `GitHub Actions CI/CD`_. This is recommended for security reasons, since
2727
the generated tokens are created for each of your projects
28-
individually and expire automatically. Otherwise you'll need to generate an
28+
individually 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
30-
indexes like :doc:`devpi <devpi:index>`, you will need to provide a
30+
indexes like :doc:`devpi <devpi:index>`, you may need to provide a
3131
username/password combination.
3232

3333
Since this guide will demonstrate uploading to both
@@ -77,7 +77,7 @@ should make GitHub run this workflow:
7777
:language: yaml
7878
:end-before: jobs:
7979

80-
This will also assure that the release workflow is only triggered
80+
This will also ensure that the release workflow is only triggered
8181
if the current commit is tagged. It is recommended you use the
8282
latest release tag; a tool like GitHub's dependabot can keep
8383
these updated regularly.
@@ -115,9 +115,11 @@ Defining a workflow job environment
115115
Now, let's add initial setup for our job that will publish to PyPI.
116116
It's a process that will execute commands that we'll define later.
117117
In this guide, we'll use the latest stable Ubuntu LTS version
118-
provided by GitHub Actions. This also defines the package index
119-
to publish to, PyPI, and grants a permission to the action that
120-
is mandatory for trusted publishing.
118+
provided by GitHub Actions. This also defines a GitHub Environment
119+
for the job to run in its context and a URL to be displayed in GitHub's
120+
UI nicely. Additionally, it allows aqcuiring an OpenID Connect token
121+
which is mandartory that the ``pypi-publish`` actions needs to
122+
implement secretless trusted publishing to PyPI.
121123

122124
.. literalinclude:: github-actions-ci-cd-sample/publish-to-test-pypi.yml
123125
:language: yaml
@@ -134,9 +136,10 @@ Finally, add the following steps at the end:
134136
:lines: 41-48
135137

136138
This step uses the `pypa/gh-action-pypi-publish`_ GitHub
137-
Action: After the stored distribution package has been
139+
Action: after the stored distribution package has been
138140
downloaded by the `download-artifact`_ action, it uploads
139141
the contents of the ``dist/`` folder into PyPI unconditionally.
142+
This job also signs the artifacts with Sigstore right after publishing them to PyPI.
140143

141144
Separate workflow for publishing to TestPyPI
142145
============================================

0 commit comments

Comments
 (0)