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
In our GitHub Repo Website, click "Use this template" and choose "Create a new Repository" option to create a copy of this repo of your own. Do as the image below:
Give your new repository a name and description as you like, better make sure it is public, then click the "Create repository" button below.
10
+
11
+

12
+
13
+
Then you will be redirected to your newly created repository. Wait a moment, and you may see your repository's web page fully displayed. Click the green "Code" button, and then choose "Codespaces" > "Create codespace on main" to start coding directly in GitHub Codespaces. Do as the image below:
14
+
15
+

16
+
17
+
Then, you can start to explore the code and workflows directly in the online environment without any local setup.
18
+
19
+
You may continue to read the rest of this README.md file in your online workspace to understand the repository structure and the workflows defined in `.github/workflows/`, and engage with us.
20
+
21
+
> If you prefer to work locally, you can also clone the repository to your local machine and keep following the instructions below.
22
+
>
23
+
> DO NOT clone the repository directly from our GitHub organisation if you want to make changes and push back to your own copy of the repository. Always create a new repository from the template first.
24
+
25
+
## Repository Overview
26
+
3
27
A minimal Python template repository for GitHub Actions demonstrations. This template includes tests (pytest) and autopep8.
4
28
5
29
Structure:
6
30
7
31
```text
8
-
app/
9
-
└─ hello.py
10
-
tests/
11
-
└─ test_hello.py
12
-
requirements.txt
13
-
.github/
14
-
└─ workflows/
15
-
├─ test.yml
16
-
├─ package.yml
17
-
└─ package-matrix.yml
32
+
.
33
+
├── LICENSE
34
+
├── README.md
35
+
├── .github
36
+
│ └── workflows
37
+
│ ├── package-matrix.yml
38
+
│ ├── package.yml
39
+
│ └── test.yml
40
+
├── .gitignore
41
+
├── app
42
+
│ ├── __init__.py
43
+
│ └── hello.py
44
+
├── assets
45
+
│ └── images
46
+
│ ├── open-in-workspace.png
47
+
│ └── workspace-structure.png
48
+
├── requirements.txt
49
+
├── solutions
50
+
│ ├── package-exercise-original.yml
51
+
│ └── package.yml
52
+
└── tests
53
+
└── test_hello.py
18
54
```
19
55
20
-
This example includes a package workflow; you'll implement it as a hands-on exercise.
This example includes a package workflow named `package.yml`; you'll implement it as a hands-on exercise later.
21
59
22
60
## Reading a simple workflow - test.yml
23
61
24
62
### First to know: about YAML syntax
25
63
26
-
YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted.
64
+

65
+
66
+
YAML is a human-friendly data serialization standard for all programming languages. It is commonly used for configuration files and in applications where data is being stored or transmitted. Github Actions workflow files are written in YAML format (\*.yml files).
67
+
68
+
To store and let GitHub Actions know how to run your workflows, you need to understand some basic YAML syntax first. Here are some key points to get you started quickly:
27
69
28
70
- Key-Value Pairs: Data is represented as key-value pairs, separated by a colon and a space (`key: value`).
29
71
@@ -56,7 +98,7 @@ YAML is a human-friendly data serialization standard for all programming languag
56
98
push:
57
99
```
58
100
59
-
- Lists: Lists are denoted by a hyphen and a space (`- item`). It can also be defined in-line using square brackets (`[item1, item2]`).
101
+
- Lists: List items are denoted by a hyphen and a space (`- item`). It can also be defined in-line using square brackets (`[item1, item2]`).
60
102
61
103
```yaml
62
104
branches:
@@ -99,33 +141,44 @@ YAML is a human-friendly data serialization standard for all programming languag
99
141
100
142
```yaml
101
143
# This is a comment. It looks awesome.
144
+
# It is a good habit to add comments in your GitHub Actions workflow files
102
145
```
103
146
104
147
**Congrats!** You now have a basic understanding of YAML syntax, which is enough for you to read and understand GitHub Actions workflow files.
105
148
106
-
### Breakdown of test.yml
149
+
### Breakdown of test.yml - Understanding a simple CI workflow
107
150
108
151
Let's break down the `test.yml` workflow file located in `.github/workflows/test.yml`.
109
152
110
153
#### Workflow Name and Trigger
111
154
112
-
```yaml
113
-
name: CI — Test & Lint
155
+
- `name`: This defines **the name of the workflow** as it will appear in the GitHub Actions interface. In this case, it's named "CI — Test & Lint".
114
156
115
-
on:
116
-
push:
117
-
branches: [main]
118
-
pull_request:
119
-
branches: [main]
120
-
```
157
+
```yaml
158
+
name: CI — Test & Lint
159
+
```
160
+
161
+

121
162
122
-
This section defines when the workflow will run. It triggers on pushes and pull requests to the `main` branch.
163
+
> PS: Never mind about the error shown in your Actions tab if you haven't set up anything yet; it will go away once you implement the workflow correctly.
164
+
165
+
- `on`: This section defines **when the workflow will run**. It triggers on pushes and pull requests to the `main` branch.
166
+
167
+
```yaml
168
+
on:
169
+
push:
170
+
branches: [main]
171
+
pull_request:
172
+
branches: [main]
173
+
```
123
174
124
175
`push`events occur when code (new commits / updates to previous commits) is pushed to the repository, while `pull_request` events happen when a pull request is opened or updated.
125
176
126
177
To use a `pull_request` trigger, you typically need to fork the repository, make changes in your fork, and then create a pull request back to the original repository.
127
178
The owner of the original repository can then review and merge your changes based on the results of the workflow triggered by the pull request.
128
179
180
+
There are many other events that can trigger workflows, such as `release`, `schedule`, `workflow_dispatch` (manual trigger), etc. You can find more details in [the official GitHub documentation](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows).
181
+
129
182
#### Jobs
130
183
131
184
Now let's look at the job definition:
@@ -155,6 +208,8 @@ To define a job in GitHub Actions, you use the `jobs` keyword followed by a uniq
155
208
- You can also set up self-hosted runners if you need specific hardware or software configurations not available in GitHub's hosted runners.
156
209
- `steps`: A list of steps that make up the job. Each step can either run a script or use an action.
157
210
211
+
There are many other properties you can define for jobs, such as `needs` (to specify job dependencies), `strategy` (for matrix builds), and more. You can find more details in [the official GitHub documentation](https://docs.github.com/en/actions/using-jobs/defining-jobs-in-a-workflow).
212
+
158
213
#### Steps
159
214
160
215
The `steps` section contains a series of actions that the job will perform.
@@ -199,7 +254,9 @@ steps:
199
254
run: pytest -q
200
255
```
201
256
202
-
## Local packaging for this project
257
+
## Add packaging workflow (exercise)
258
+
259
+
### How to package this project locally (for reference)
203
260
204
261
You can quickly build a standalone executable for this small project with PyInstaller.
205
262
@@ -225,11 +282,19 @@ python -m venv .venv
225
282
dir dist
226
283
```
227
284
228
-
## Add packaging workflow (exercise)
285
+
### Implement packaging workflow in GitHub Actions
286
+
287
+
Now you can try implement a simple sequential workflow that first builds macOS arm64 and then Windows x64 packages in `.github/workflows/package.yml` in your codespace.
288
+
289
+
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`). Do NOT open it until you have tried your best to implement it on your own.
290
+
291
+
You can now test your workflow by committing and pushing your changes to the `main` branch of your repository, or you can manually trigger the workflow from the "Actions" tab in your repository.
292
+
293
+

229
294
230
-
You can try implement a simple sequential workflow that first builds macOS arm64 and then Windows x64 packages in `.github/workflows/package.yml`.
295
+

231
296
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`).
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.
Going back to the release page after the workflow succeeded, as you can see, the workflow has successfully built and attached multiple artifacts to the release.
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