Skip to content

Commit 6254cd3

Browse files
committed
docs: add images
1 parent daec6b4 commit 6254cd3

21 files changed

+113
-32
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,6 @@ cython_debug/
205205
marimo/_static/
206206
marimo/_lsp/
207207
__marimo__/
208+
209+
.DS_Store
210+
Thumbs.db

README.md

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,71 @@
11
# Github Action Tutorial
22

3+
## Quick Start
4+
5+
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:
6+
7+
![create-repo-btn](./assets/images/create-repo-btn.png)
8+
9+
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+
![create-repo](./assets/images/create-repo.png)
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+
![alt text](./assets/images/create-cs.png)
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+
327
A minimal Python template repository for GitHub Actions demonstrations. This template includes tests (pytest) and autopep8.
428

529
Structure:
630

731
```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
1854
```
1955

20-
This example includes a package workflow; you'll implement it as a hands-on exercise.
56+
![workflow-structure](assets/images/workspace-structure.png)
57+
58+
This example includes a package workflow named `package.yml`; you'll implement it as a hands-on exercise later.
2159

2260
## Reading a simple workflow - test.yml
2361

2462
### First to know: about YAML syntax
2563

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+
![yaml](./assets/images/yaml.png)
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:
2769

2870
- Key-Value Pairs: Data is represented as key-value pairs, separated by a colon and a space (`key: value`).
2971

@@ -56,7 +98,7 @@ YAML is a human-friendly data serialization standard for all programming languag
5698
push:
5799
```
58100

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]`).
60102

61103
```yaml
62104
branches:
@@ -99,33 +141,44 @@ YAML is a human-friendly data serialization standard for all programming languag
99141

100142
```yaml
101143
# This is a comment. It looks awesome.
144+
# It is a good habit to add comments in your GitHub Actions workflow files
102145
```
103146

104147
**Congrats!** You now have a basic understanding of YAML syntax, which is enough for you to read and understand GitHub Actions workflow files.
105148

106-
### Breakdown of test.yml
149+
### Breakdown of test.yml - Understanding a simple CI workflow
107150

108151
Let's break down the `test.yml` workflow file located in `.github/workflows/test.yml`.
109152

110153
#### Workflow Name and Trigger
111154

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".
114156

115-
on:
116-
push:
117-
branches: [main]
118-
pull_request:
119-
branches: [main]
120-
```
157+
```yaml
158+
name: CI — Test & Lint
159+
```
160+
161+
![wf-name](./assets/images/wf-name.png)
121162

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+
```
123174

124175
`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.
125176

126177
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.
127178
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.
128179

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+
129182
#### Jobs
130183

131184
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
155208
- You can also set up self-hosted runners if you need specific hardware or software configurations not available in GitHub's hosted runners.
156209
- `steps`: A list of steps that make up the job. Each step can either run a script or use an action.
157210

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+
158213
#### Steps
159214

160215
The `steps` section contains a series of actions that the job will perform.
@@ -199,7 +254,9 @@ steps:
199254
run: pytest -q
200255
```
201256

202-
## Local packaging for this project
257+
## Add packaging workflow (exercise)
258+
259+
### How to package this project locally (for reference)
203260

204261
You can quickly build a standalone executable for this small project with PyInstaller.
205262

@@ -225,11 +282,19 @@ python -m venv .venv
225282
dir dist
226283
```
227284

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+
![commit](./assets/images/commit.png)
229294

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+
![running](./assets/images/running.png)
231296

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`).
297+
![package-result](./assets/images/package-result.png)
233298

234299
## Release flow (automatic packaging and upload assets to release)
235300

@@ -245,20 +310,33 @@ To allow the workflow to upload assets to a release, you need to grant it the ne
245310

246311
1. Go to your repository on GitHub.
247312
2. Click on the "Settings" tab.
248-
3. In the left sidebar, click on "Actions" under the "Security" section.
313+
![setting-route](./assets/images/setting-route.png)
314+
3. In the left sidebar, click on "Actions" > "General" under the "Security" section.
249315
4. Scroll down to the "Workflow permissions" section.
250316
5. Select the option "Read and write permissions".
317+
![read-and-write](./assets/images/read-and-write.png)
251318
6. Click the "Save" button to apply the changes.
252319

253320
### Now try to create a release
254321

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".
322+
1. Go back to home page of your repo.
323+
![create-release-btn](./assets/images/create-release-btn.png)
324+
2. Enter a tag version (e.g., `v1.0.0`) and fill in the release title and description you like.
325+
![type-tag](./assets/images/type-tag.png)
326+
![create-tag](./assets/images/create-tag.png)
327+
![publish-release](./assets/images/publish-release.png)
328+
3. Click on "Publish release".
259329

260330
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.
261331

332+
![auto-build](./assets/images/auto-build.png)
333+
334+
![matrix-succeed](./assets/images/matrix-succeed.png)
335+
336+
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.
337+
338+
![release-page-final](./assets/images/release-page-final.png)
339+
262340
## The end
263341

264342
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.

assets/images/auto-build.png

43.4 KB
Loading

assets/images/commit.png

1.09 MB
Loading

assets/images/create-cs.png

903 KB
Loading
683 KB
Loading

assets/images/create-repo-btn.png

1.03 MB
Loading

assets/images/create-repo.png

1.04 MB
Loading

assets/images/create-tag.png

38.7 KB
Loading

assets/images/matrix-succeed.png

1020 KB
Loading

0 commit comments

Comments
 (0)