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
Copy file name to clipboardExpand all lines: README.md
+32-18Lines changed: 32 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,7 @@ requirements.txt
14
14
└─ workflows/
15
15
├─ test.yml
16
16
├─ package.yml
17
-
├─ package-matrix.yml
18
-
└─ release.yml
17
+
└─ package-matrix.yml
19
18
```
20
19
21
20
This example includes a package workflow; you'll implement it as a hands-on exercise.
@@ -65,7 +64,7 @@ YAML is a human-friendly data serialization standard for all programming languag
65
64
- develop
66
65
```
67
66
68
-
**Or**
67
+
**Or the following expression, they are equivalent**
69
68
70
69
```yaml
71
70
branches: [main, develop]
@@ -99,7 +98,7 @@ YAML is a human-friendly data serialization standard for all programming languag
99
98
- Comments: Lines starting with `#` are comments and are ignored by parsers.
100
99
101
100
```yaml
102
-
# This is a comment
101
+
# This is a comment. It looks awesome.
103
102
```
104
103
105
104
**Congrats!** You now have a basic understanding of YAML syntax, which is enough for you to read and understand GitHub Actions workflow files.
@@ -151,8 +150,9 @@ To define a job in GitHub Actions, you use the `jobs` keyword followed by a uniq
151
150
- GitHub Actions provides a variety of hosted runners with different operating systems and configurations. The three most common options are:
152
151
- `ubuntu-latest`: The latest stable version of Ubuntu Linux.
153
152
- `windows-latest`: The latest stable version of Windows Server.
154
-
- `macos-latest`: The latest stable version of macOS.
155
-
You can choose a appropriate runner according to [the docs provided by GitHub](https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/choose-the-runner-for-a-job#choosing-github-hosted-runners) based on your project's requirements and the environment you need for your workflows.
153
+
- `macos-latest`: The latest stable version of macOS.
154
+
- You can choose a appropriate runner according to [the docs provided by GitHub](https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/choose-the-runner-for-a-job#choosing-github-hosted-runners) based on your project's requirements and the environment you need for your workflows.
155
+
- You can also set up self-hosted runners if you need specific hardware or software configurations not available in GitHub's hosted runners.
156
156
- `steps`: A list of steps that make up the job. Each step can either run a script or use an action.
157
157
158
158
#### Steps
@@ -167,14 +167,14 @@ steps:
167
167
# This is a common first step in most workflows that need to work with the repository's code.
168
168
- name: Checkout Repo
169
169
uses: actions/checkout@v4
170
-
170
+
171
171
# Set up Python environment - Automatically install Python for the job efficiently
172
172
# In this way, you don't need to manually install Python using shell commands
173
173
# This action step handles it for you.
174
174
- name: Set up Python
175
175
uses: actions/setup-python@v4
176
176
with:
177
-
python-version: "3.11"
177
+
python-version: '3.11'
178
178
179
179
# Install dependencies
180
180
# This step ensures that all necessary Python packages listed in requirements.txt are installed
@@ -231,20 +231,34 @@ You can try implement a simple sequential workflow that first builds macOS arm64
231
231
232
232
If you have finished composing or encountered some troubles, you may see `solutions/package.yml` — this builds the two packages in sequence and uploads two artifacts (`hello-macos-arm64` and `hello-windows-x64`).
233
233
234
-
## Release flow (automatic packaging and release assets)
234
+
## Release flow (automatic packaging and upload assets to release)
235
235
236
-
The repository includes a pair of workflows to create a tag, publish a release, and attach build artifacts to the release:
236
+
The repository includes a workflow that automatically builds packages for multiple OS/Python combinations and attaches the build artifacts to a GitHub Release.
237
237
238
-
- `release.yml`— creates a `vX.Y.Z` tag from the workflow_dispatch input and publishes a GitHub Release.
239
238
- `package-matrix.yml`— runs packaging on `ubuntu`, `macos`, and `windows` using a matrix and attaches the build artifacts to the release when the workflow is triggered by the `release` event.
240
239
241
-
How it works:
240
+
### Wait, your workflow need some permissions to upload assets to release
241
+
242
+
To allow the workflow to upload assets to a release, you need to grant it the necessary permissions. By default, GitHub Actions workflows have read-only access to the repository contents. To upload assets to a release, you need to ensure that the workflow has write permissions.
243
+
244
+
#### How to do that
245
+
246
+
1. Go to your repository on GitHub.
247
+
2. Click on the "Settings" tab.
248
+
3. In the left sidebar, click on "Actions" under the "Security" section.
249
+
4. Scroll down to the "Workflow permissions" section.
250
+
5. Select the option "Read and write permissions".
251
+
6. Click the "Save" button to apply the changes.
252
+
253
+
### Now try to create a release
254
+
255
+
1. Go to the Releases section of the repository.
256
+
2. Click on "Draft a new release".
257
+
3. Enter a tag version (e.g., `v1.0.0`) and fill in the release title and description you like.
258
+
4. Click on "Publish release".
242
259
243
-
1. Use the **Create Release** workflow in the Actions tab.
244
-
2. The workflow will create the tag base on your input and publish the release; this publishes a `release` event.
245
-
3. `package-matrix.yml` is configured to run when a release is published; it will build packages for each OS/Python combination in the matrix and attach each artifact to the release.
260
+
Once the release is published, the `package-matrix.yml` workflow will automatically run (so do the workflow defined by `package.yml` that you have just implemented, but now let's focus on `package-matrix.yml`), building the packages for each OS/Python combination defined in the matrix and attaching the resulting artifacts to the release.
246
261
247
-
Notes:
262
+
## The end
248
263
249
-
- The build artifacts are attached to the Release created by `release.yml`.
250
-
- Packaging is also possible manually by running the `Package — Build & Upload using Matrix` workflow.
264
+
Now you may return to our [Weekly Sharing Session Repo](https://github.com/CompPsyUnion/2526-weekly-session/tree/main/Contents/GitHubAction) and continue to the end of our today's session.
0 commit comments