Skip to content

Commit 8c74bf6

Browse files
lwassermathematicalmichaelucoderymihaimaruseacsneakers-the-rat
authored
Apply suggestions from code review
Co-authored-by: Michael Pilosov, PhD <[email protected]> Co-authored-by: Jeremiah Paige <[email protected]> Co-authored-by: Mihai Maruseac <[email protected]> Co-authored-by: Jonny Saunders <[email protected]>
1 parent 135f0a8 commit 8c74bf6

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

tutorials/trusted-publishing.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Setup Trusted Publishing for secure and automated publishing via GitHub Actions
77

8-
In the previous Python packaging lessons, you've learned:
8+
In the previous Python packaging lessons, you learned:
99

1010
1. [How to create a Python package](create-python-package)
1111
1. How to publish the code to [PyPI](publish-pypi) and [Conda](publish-conda-forge)
@@ -24,15 +24,15 @@ In this lesson you will learn how to:
2424

2525
GitHub Actions[^gha] is an infrastructure provided by GitHub to automate
2626
software workflows, straight from the GitHub repository of the project. You can
27-
configure automated testing for every pull request, automated publishing of
28-
documentation, automated creation of webpages for the project, and even automate
27+
configure automated testing for every pull request, automate publishing of
28+
documentation, automate creation of webpages for the project, and even automate
2929
the release process. For this lesson we will only focus on the release process
3030
itself.
3131

3232
:::{admonition} Learning Objectives
3333
:class: tip
3434

35-
This tutorial assumes that your project is published to GitHub and that you want
35+
This tutorial assumes that your project is hosted to GitHub and that you want
3636
to publish a package from your project to PyPI.
3737
:::
3838

@@ -64,15 +64,15 @@ This gives a name to the workflow. It allows you to quickly find all runs of
6464
this GitHub Action on the "Actions" tab in the GitHub repository.
6565
6666
:::{figure-md} github-actions-release-workflows-summary
67-
<img src="../images/tutorials/github-actions-release-workflows-summary.png" alt='Graphic showing an example of a configured workflow for the release. On the top, in the red box labeled "1" you see the "Actions" tab of the GitHub repository. On the left, in the red box labeled "2" you can see the name of the workflow, as configured in this step. Finally, in the center, in the red box labeled "3" you can see several runs of the workflow, for the "1.0" and "1.0.1" releases of the package.' width="700px">
67+
<img src="../images/tutorials/github-actions-release-workflows-summary.png" alt='Graphic showing an example of a configured workflow for the release. On the top, in the red box labeled "1" you see the "Actions" tab of the GitHub repository. On the left, in the red box labeled "2" you can see the name of the workflow, "Release," as configured in this step. Finally, in the center, in the red box labeled "3" you can see several runs of the workflow, for the "1.0" and "1.0.1" releases of the package.' width="700px">
6868
6969
This image shows an example of a configured workflow for the release. On the top, in the red box labeled "1" you see the "Actions" tab of the GitHub repository. On the left, in the red box labeled "2" you can see the name of the workflow, as configured in this step. Finally, in the center, in the red box labeled "3" you can see several runs of the workflow, for the "1.0" and "1.0.1" releases of the package.
7070
:::
7171
7272
### Step 2: Add triggers to the workflow
7373
74-
Every GitHub Actions workflow runs only when certain conditions are met. A
75-
release workflow should only run when the repository owner creates a new release
74+
Every GitHub Actions workflow runs only when [certain conditions](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) are met. A
75+
release workflow should only run when the repository owner creates a new [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository)
7676
for the package. Add the following to the `release.yaml` file:
7777

7878
```yaml
@@ -84,7 +84,10 @@ on:
8484

8585
### Step 3: Configure the jobs in the workflow
8686

87-
When triggered, the GitHub Actions runs multiple jobs. We have to configure at
87+
A GitHub Actions *workflow* file can contain multiple *jobs* that run independently, each of which can have multiple *steps.*
88+
When triggered, the GitHub Actions runs all the jobs in a workflow[^conditionally]. We have to configure at
89+
90+
[^conditionally]: Jobs and steps can also have [conditional logic](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idif) that makes them only run in certain circumstances.
8891
least one job in the workflow file.
8992

9093
For a release job, we need to clone the repository and then use `hatch` to build
@@ -104,7 +107,7 @@ jobs:
104107
- run: hatch build
105108
```
106109

107-
:::{admonition} Hardening the GitHub Actions workflow
110+
:::{admonition} Securing the GitHub Actions workflow
108111

109112
There are several improvements we can make to the GitHub Actions workflow we
110113
just configured to improve security and readability.
@@ -140,11 +143,11 @@ jobs:
140143

141144
:::
142145

143-
Now, you can commit the `.github/workflows/release.yaml` file to the repository.
146+
Now, you can commit the `.github/workflows/release.yaml` file to the repository and push to GitHub.
144147

145148
At this point, if you create a new release for your project on GitHub, the
146149
configured workflow should run and build a wheel for you. Unfortunately, the
147-
wheel is only available on the runner.
150+
wheel is only available on the runner, and will be deleted at the end of the workflow run.
148151

149152
### Step 4: Upload the built artifact to the GitHub Artifacts
150153

@@ -165,8 +168,7 @@ the following to the `release.yaml` file:
165168
:class: tip
166169

167170
We have configured the artifact to be deleted after 1 day. The artifacts storage
168-
on GitHub actions is temporary, and users should not be getting the package from
169-
here.
171+
on GitHub actions is temporary; users should not be getting the package from here.
170172

171173
We have also configured the release job to error if the `dist/` directory does
172174
not exist. This means that `hatch build` (from the previous step) failed to
@@ -205,7 +207,7 @@ still need to upload it to PyPI. We could upload the package from the same job,
205207
but it is better to create a separate one, to maintain separation of concerns.
206208
This is why in the previous section we uploaded the artifact to the temporary
207209
storage -- in the new job, we will download the package from there and upload it
208-
to PyPI. Since this job does nothing else, there is no possibility that the
210+
to PyPI. Since the `build` job does nothing else, there is no possibility that the
209211
package could get compromised before the release.
210212

211213
### Step 1: Add the upload job
@@ -216,7 +218,7 @@ the previous section:
216218
```yaml
217219
publish_release_to_pypi:
218220
name: Publish release to PyPI
219-
needs: [build_package]
221+
needs: [build_package] # only run if `build_package` succeeded
220222
runs-on: ubuntu-latest
221223
environment:
222224
name: pypi
@@ -252,8 +254,8 @@ were pasting it directly in the workflow file. Furthermore, accidental leakage
252254
of the token could allow attackers to publish new packages in your name, until
253255
you discover the compromise and revoke the leaked credential.
254256

255-
To prevent these incidents and improve security, supply chain security
256-
developers created Trusted Publishing. This allows registering publishers on
257+
To prevent these incidents and improve supply chain security
258+
developers created [Trusted Publishing](https://docs.pypi.org/trusted-publishers/). This allows registering publishers on
257259
PyPI and mapping them to the automation workflow that is allowed to publish the
258260
package.
259261

0 commit comments

Comments
 (0)