You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<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">
68
68
69
69
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.
70
70
:::
71
71
72
72
### Step 2: Add triggers to the workflow
73
73
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)
76
76
for the package. Add the following to the `release.yaml` file:
77
77
78
78
```yaml
@@ -84,7 +84,10 @@ on:
84
84
85
85
### Step 3: Configure the jobs in the workflow
86
86
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.
88
91
least one job in the workflow file.
89
92
90
93
For a release job, we need to clone the repository and then use `hatch` to build
@@ -104,7 +107,7 @@ jobs:
104
107
- run: hatch build
105
108
```
106
109
107
-
:::{admonition} Hardening the GitHub Actions workflow
110
+
:::{admonition} Securing the GitHub Actions workflow
108
111
109
112
There are several improvements we can make to the GitHub Actions workflow we
110
113
just configured to improve security and readability.
@@ -140,11 +143,11 @@ jobs:
140
143
141
144
:::
142
145
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.
144
147
145
148
At this point, if you create a new release for your project on GitHub, the
146
149
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.
148
151
149
152
### Step 4: Upload the built artifact to the GitHub Artifacts
150
153
@@ -165,8 +168,7 @@ the following to the `release.yaml` file:
165
168
:class: tip
166
169
167
170
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.
170
172
171
173
We have also configured the release job to error if the `dist/` directory does
172
174
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,
205
207
but it is better to create a separate one, to maintain separation of concerns.
206
208
This is why in the previous section we uploaded the artifact to the temporary
207
209
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
209
211
package could get compromised before the release.
210
212
211
213
### Step 1: Add the upload job
@@ -216,7 +218,7 @@ the previous section:
216
218
```yaml
217
219
publish_release_to_pypi:
218
220
name: Publish release to PyPI
219
-
needs: [build_package]
221
+
needs: [build_package] # only run if `build_package` succeeded
220
222
runs-on: ubuntu-latest
221
223
environment:
222
224
name: pypi
@@ -252,8 +254,8 @@ were pasting it directly in the workflow file. Furthermore, accidental leakage
252
254
of the token could allow attackers to publish new packages in your name, until
253
255
you discover the compromise and revoke the leaked credential.
254
256
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
257
259
PyPI and mapping them to the automation workflow that is allowed to publish the
0 commit comments