@@ -132,28 +132,12 @@ date. Once Dependabot is enabled, it will update these hashes for you in the fut
132
132
133
133
Thus, the workflow that you should use should be similar to :
134
134
135
- ` ` ` {literalinclude} ../examples/pure-hatch/.github/release.yml
136
- :language: python
137
- :lines: 10-20
135
+ ` ` ` {literalinclude} ../examples/pure-hatch/.github/workflows/ release.yml
136
+ :language: yaml
137
+ :lines: 1-23
138
138
139
139
` ` `
140
140
141
-
142
- ` ` ` yaml}
143
- jobs:
144
- build_package:
145
- name: Build the package
146
- runs-on: ubuntu-latest
147
- steps:
148
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0
149
- with:
150
- persist-credentials: false
151
- - name: Set up Hatch
152
- uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
153
- - name: Build artifacts
154
- run: hatch build
155
- ` ` `
156
-
157
141
Now, you can commit the `.github/workflows/release.yaml` file to the repository and push to GitHub.
158
142
159
143
At this point, if you create a new release for your project on GitHub, the
@@ -166,13 +150,10 @@ You need to add one more step to the job definition to be able to access the
166
150
wheel. You will upload it to the artifacts temporary area[^github-artifacts]. Add
167
151
the following to the `release.yaml` file :
168
152
169
- ` ` ` yaml
170
- - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
171
- with:
172
- path: dist/
173
- name: dist.zip
174
- if-no-files-found: error
175
- retention-days: 1
153
+ ` ` ` {literalinclude} ../examples/pure-hatch/.github/workflows/release.yml
154
+ :language: yaml
155
+ :lines: 24-29
156
+
176
157
` ` `
177
158
178
159
:::{admonition} Upload artifacts parameters
@@ -230,20 +211,11 @@ package could get compromised before the release.
230
211
In the `release.yaml` file, add the following new job, after the job defined in
231
212
the previous section :
232
213
233
- ` ` ` yaml
234
- publish_release_to_pypi:
235
- name: Publish release to PyPI
236
- needs: [build_package] # only run if ` build_package` succeeded
237
- runs-on : ubuntu-latest
238
- environment :
239
- name : pypi
240
- url : <URL TO YOUR PROJECT HERE>
241
- steps :
242
- - uses : actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
243
- with :
244
- name : dist.zip
245
- path : dist/
246
- - uses : pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
214
+
215
+ ` ` ` {literalinclude} ../examples/pure-hatch/.github/workflows/release.yml
216
+ :language: yaml
217
+ :lines: 31-46
218
+
247
219
` ` `
248
220
249
221
:::{admonition} Make sure to change the URL
@@ -321,65 +293,23 @@ the following information:
321
293
Once you fill in this form and click "Add" the publisher is configured and can
322
294
be used to publish new releases of your package.
323
295
324
- :::{admonition} Fully hardened GitHub Actions release workflow
296
+ # # Fully hardened GitHub Actions release workflow
325
297
326
- For better security it is recommended to also control the permissions of the
298
+ For better security, it is also recommended to control the permissions of the
327
299
GitHub token used within each job of the workflow. The permissions should be
328
300
scoped at job level and be as minimal as possible. A workflow that configures
329
301
trusted publishing and also does this is the following :
330
302
331
- ` ` ` yaml
332
- name: Release
333
-
334
- on:
335
- release:
336
- types:
337
- - published
303
+ ` ` ` {literalinclude} ../examples/pure-hatch/.github/workflows/release.yml
304
+ :language: yaml
338
305
339
- permissions: {} # no permissions to the token at global level
340
-
341
- jobs:
342
- build_package:
343
- name: Build the package
344
- runs-on: ubuntu-latest
345
- permissions:
346
- contents: read # this job only needs read access
347
- steps:
348
- - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
349
- with:
350
- persist-credentials: false
351
- - name: Set up Hatch
352
- uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
353
- - name: Build artifacts
354
- run: hatch build
355
- - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
356
- with:
357
- path: dist/
358
- name: dist.zip
359
- if-no-files-found: error
360
- retention-days: 1
361
-
362
- publish_release_to_pypi:
363
- name: Publish release to PyPI
364
- needs: [build_package]
365
- runs-on: ubuntu-latest
366
- environment:
367
- name: pypi
368
- url: <URL TO YOUR PROJECT HERE>
369
- permissions:
370
- contents: read # this job needs read access
371
- id-token: write # but also needs to be able to write the publishing token
372
- steps:
373
- - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
374
- with:
375
- name: dist.zip
376
- path: dist/
377
- - uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
378
306
` ` `
379
307
380
308
You can copy the above into your `release.yaml` file. You only need to update
381
309
the `url:` field and configure trusted publishing on PyPI.
382
310
311
+ :::{note}
312
+ The workflow above should be up to date with the current versions of GitHub actions. However, it's good to turn on Dependabot to update the action versions in the future.
383
313
:: :
384
314
385
315
# # You have enabled trusted publishing for your project
0 commit comments