Skip to content

Commit f47b347

Browse files
committed
📝🎨 Put OIDC on pedestal @ README
This patch makes sure that the new users would go for the secretless publishing when integrating the action, from the beginning.
1 parent 7a1a355 commit f47b347

File tree

1 file changed

+37
-46
lines changed

1 file changed

+37
-46
lines changed

Diff for: README.md

+37-46
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,17 @@ tag, or a full Git commit SHA.
2323

2424
## Usage
2525

26-
To use the action add the following step to your workflow file (e.g.
27-
`.github/workflows/main.yml`)
28-
29-
30-
```yml
31-
- name: Publish a Python distribution to PyPI
32-
uses: pypa/gh-action-pypi-publish@release/v1
33-
with:
34-
password: ${{ secrets.PYPI_API_TOKEN }}
35-
```
36-
37-
> **Pro tip**: instead of using branch pointers, like `unstable/v1`, pin
38-
versions of Actions that you use to tagged versions or sha1 commit identifiers.
39-
This will make your workflows more secure and better reproducible, saving you
40-
from sudden and unpleasant surprises.
41-
42-
A common use case is to upload packages only on a tagged commit, to do so add a
43-
filter to the step:
44-
45-
46-
```yml
47-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
48-
```
49-
50-
So the full step would look like:
51-
52-
53-
```yml
54-
- name: Publish package
55-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
56-
uses: pypa/gh-action-pypi-publish@release/v1
57-
with:
58-
password: ${{ secrets.PYPI_API_TOKEN }}
59-
```
60-
61-
The example above uses the new [API token][PyPI API token] feature of
62-
PyPI, which is recommended to restrict the access the action has.
63-
64-
The secret used in `${{ secrets.PYPI_API_TOKEN }}` needs to be created on the
65-
settings page of your project on GitHub. See [Creating & using secrets].
66-
67-
6826
### Trusted publishing
6927

7028
> **NOTE**: Trusted publishing is sometimes referred to by its
7129
> underlying technology -- OpenID Connect, or OIDC for short.
7230
> If you see references to "OIDC publishing" in the context of PyPI,
7331
> this is what they're referring to.
7432
33+
This example jumps right into the current best practice. If you want to
34+
go for less secure scoped PyPI API tokens, check out [how to specify
35+
username and password].
36+
7537
This action supports PyPI's [trusted publishing]
7638
implementation, which allows authentication to PyPI without a manually
7739
configured API token or username/password combination. To perform
@@ -82,6 +44,7 @@ To enter the trusted publishing flow, configure this action's job with the
8244
`id-token: write` permission and **without** an explicit username or password:
8345

8446
```yaml
47+
# .github/workflows/ci-cd.yml
8548
jobs:
8649
pypi-publish:
8750
name: Upload release to PyPI
@@ -98,6 +61,11 @@ jobs:
9861
uses: pypa/gh-action-pypi-publish@release/v1
9962
```
10063
64+
> **Pro tip**: instead of using branch pointers, like `unstable/v1`, pin
65+
versions of Actions that you use to tagged versions or sha1 commit identifiers.
66+
This will make your workflows more secure and better reproducible, saving you
67+
from sudden and unpleasant surprises.
68+
10169
Other indices that support trusted publishing can also be used, like TestPyPI:
10270

10371
```yaml
@@ -114,6 +82,13 @@ _(don't forget to update the environment name to `testpypi` or similar!)_
11482
> or test environment won't be able to elevate privileges while flying under
11583
> the radar.
11684

85+
A common use case is to upload packages only on a tagged commit, to do so add a
86+
filter to the job:
87+
88+
```yml
89+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
90+
```
91+
11792

11893
## Non-goals
11994

@@ -149,7 +124,7 @@ by putting them into the `dist/` folder prior to running this Action.
149124
For best results, figure out what kind of workflow fits your
150125
project's specific needs.
151126

152-
For example, you could implement a parallel workflow that
127+
For example, you could implement a parallel job that
153128
pushes every commit to TestPyPI or your own index server,
154129
like `devpi`. For this, you'd need to (1) specify a custom
155130
`repository-url` value and (2) generate a unique version
@@ -158,8 +133,11 @@ The latter is possible if you use `setuptools_scm` package but
158133
you could also invent your own solution based on the distance
159134
to the latest tagged commit.
160135

161-
You'll need to create another token for a separate host and then
162-
[save it as a GitHub repo secret][Creating & using secrets].
136+
You'll need to create another token for a separate host and then [save it as a
137+
GitHub repo secret][Creating & using secrets] under an environment used in
138+
your job. Though, passing a password would disable the secretless [trusted
139+
publishing] so it's better to configure it instead, when publishing to TestPyPI
140+
and not something custom.
163141

164142
The action invocation in this case would look like:
165143
```yml
@@ -180,7 +158,6 @@ would now look like:
180158
- name: Publish package to PyPI
181159
uses: pypa/gh-action-pypi-publish@release/v1
182160
with:
183-
password: ${{ secrets.PYPI_API_TOKEN }}
184161
packages-dir: custom-dir/
185162
```
186163

@@ -245,6 +222,18 @@ specify a custom username and password pair. This is how it's done.
245222
password: ${{ secrets.DEVPI_PASSWORD }}
246223
```
247224

225+
The secret used in `${{ secrets.DEVPI_PASSWORD }}` needs to be created on the
226+
environment page under the settings of your project on GitHub.
227+
See [Creating & using secrets].
228+
229+
In the past, when publishing to PyPI, the most secure way of the access scoping
230+
for automatic publishing was to use the [API tokens][PyPI API token] feature of
231+
PyPI. One would make it project-scoped and save as an environment-bound secret
232+
in their GitHub repository settings, naming it `${{ secrets.PYPI_API_TOKEN }}`,
233+
for example. See [Creating & using secrets]. This is no longer encouraged when
234+
publishing to PyPI or TestPyPI, in favor of [trusted publishing].
235+
236+
248237
## License
249238

250239
The Dockerfile and associated scripts and documentation in this project
@@ -280,3 +269,5 @@ https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md
280269

281270
[warehouse#12965]: https://github.com/pypi/warehouse/issues/12965
282271
[trusted publishing]: https://docs.pypi.org/trusted-publishers/
272+
273+
[how to specify username and password]: #specifying-a-different-username

0 commit comments

Comments
 (0)