@@ -23,55 +23,17 @@ tag, or a full Git commit SHA.
23
23
24
24
## Usage
25
25
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
-
68
26
### Trusted publishing
69
27
70
28
> ** NOTE** : Trusted publishing is sometimes referred to by its
71
29
> underlying technology -- OpenID Connect, or OIDC for short.
72
30
> If you see references to "OIDC publishing" in the context of PyPI,
73
31
> this is what they're referring to.
74
32
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
+
75
37
This action supports PyPI's [ trusted publishing]
76
38
implementation, which allows authentication to PyPI without a manually
77
39
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
82
44
` id-token: write ` permission and ** without** an explicit username or password:
83
45
84
46
``` yaml
47
+ # .github/workflows/ci-cd.yml
85
48
jobs :
86
49
pypi-publish :
87
50
name : Upload release to PyPI
98
61
uses : pypa/gh-action-pypi-publish@release/v1
99
62
` ` `
100
63
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
+
101
69
Other indices that support trusted publishing can also be used, like TestPyPI :
102
70
103
71
` ` ` yaml
@@ -114,6 +82,13 @@ _(don't forget to update the environment name to `testpypi` or similar!)_
114
82
> or test environment won't be able to elevate privileges while flying under
115
83
> the radar.
116
84
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
+
117
92
118
93
# # Non-goals
119
94
@@ -149,7 +124,7 @@ by putting them into the `dist/` folder prior to running this Action.
149
124
For best results, figure out what kind of workflow fits your
150
125
project's specific needs.
151
126
152
- For example, you could implement a parallel workflow that
127
+ For example, you could implement a parallel job that
153
128
pushes every commit to TestPyPI or your own index server,
154
129
like `devpi`. For this, you'd need to (1) specify a custom
155
130
` repository-url` value and (2) generate a unique version
@@ -158,8 +133,11 @@ The latter is possible if you use `setuptools_scm` package but
158
133
you could also invent your own solution based on the distance
159
134
to the latest tagged commit.
160
135
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.
163
141
164
142
The action invocation in this case would look like :
165
143
` ` ` yml
@@ -180,7 +158,6 @@ would now look like:
180
158
- name: Publish package to PyPI
181
159
uses: pypa/gh-action-pypi-publish@release/v1
182
160
with:
183
- password: ${{ secrets.PYPI_API_TOKEN }}
184
161
packages-dir: custom-dir/
185
162
` ` `
186
163
@@ -245,6 +222,18 @@ specify a custom username and password pair. This is how it's done.
245
222
password: ${{ secrets.DEVPI_PASSWORD }}
246
223
` ` `
247
224
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
+
248
237
# # License
249
238
250
239
The Dockerfile and associated scripts and documentation in this project
@@ -280,3 +269,5 @@ https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md
280
269
281
270
[warehouse#12965]: https://github.com/pypi/warehouse/issues/12965
282
271
[trusted publishing] : https://docs.pypi.org/trusted-publishers/
272
+
273
+ [how to specify username and password] : # specifying-a-different-username
0 commit comments