Skip to content

Commit 7c525be

Browse files
committed
feat: add main programme and docs
1 parent e1f5731 commit 7c525be

File tree

12 files changed

+347
-1
lines changed

12 files changed

+347
-1
lines changed

.github/workflows/package.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Simple Package — Sequential macOS arm64 & Windows x64
2+
3+
on:
4+
workflow_dispatch: # manual trigger
5+
push:
6+
tags: ['v*']
7+
8+
jobs:
9+
build-macos-arm64:
10+
name: Build macOS arm64
11+
runs-on: macos-14
12+
steps:
13+
- name: Check out
14+
uses: actions/checkout@v4
15+
- name: Show runner arch
16+
run: uname -m || true
17+
- name: Setup Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.11'
21+
- name: Install deps
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
- name: Build with PyInstaller (macOS arm64)
26+
run: |
27+
pyinstaller --onefile app/hello.py -n hello-macos-arm64
28+
- name: Debug dist
29+
run: ls -la dist || true
30+
- name: Upload macOS artifact
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: hello-macos-arm64
34+
path: dist/hello-macos-arm64
35+
36+
build-windows-x64:
37+
name: Build Windows x64
38+
needs: build-macos-arm64
39+
runs-on: windows-latest
40+
steps:
41+
- name: Check out
42+
uses: actions/checkout@v4
43+
- name: Setup Python
44+
uses: actions/setup-python@v4
45+
with:
46+
python-version: '3.11'
47+
- name: Install deps
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install -r requirements.txt
51+
- name: Build with PyInstaller (Windows x64)
52+
shell: pwsh
53+
run: |
54+
pyinstaller --onefile app/hello.py -n hello-windows-x64
55+
- name: Debug dist
56+
shell: pwsh
57+
run: dir dist || true
58+
- name: Upload Windows artifact
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: hello-windows-x64.exe
62+
path: dist/hello-windows-x64.exe

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI — Test & Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.10, 3.11]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
- name: Run autopep8 check
26+
run: |
27+
pip install autopep8
28+
autopep8 --diff --recursive app tests
29+
- name: Run tests
30+
run: pytest -q

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"cSpell.words": [
3+
"autopep",
4+
"onefile",
5+
"pyinstaller",
6+
"pytest",
7+
"venv"
8+
]
9+
}

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
# github-action-tutorial
1+
# Github Action Tutorial
2+
3+
A minimal Python template repository for GitHub Actions demonstrations. This template includes tests (pytest) and autopep8.
4+
5+
Structure:
6+
7+
```text
8+
app/
9+
└─ hello.py
10+
tests/
11+
└─ test_hello.py
12+
requirements.txt
13+
.github/workflows/test.yml
14+
```
15+
16+
This example intentionally does not include a packaging workflow; you'll add it as a hands-on exercise.
17+
18+
## Local packaging
19+
20+
You can quickly build a standalone executable for this small project with PyInstaller.
21+
22+
On macOS/Linux:
23+
24+
```bash
25+
python3 -m venv .venv
26+
source .venv/bin/activate # macOS/Linux
27+
.venv/bin/pip install -r requirements.txt
28+
.venv/bin/pyinstaller --onefile app/hello.py
29+
ls -la dist
30+
```
31+
32+
On Windows PowerShell:
33+
34+
```powershell
35+
py -3 -m venv .venv
36+
.\.venv\Scripts\Activate.ps1
37+
.venv\Scripts\pip.exe install -r requirements.txt
38+
.venv\Scripts\pyinstaller.exe --onefile app/hello.py
39+
dir dist
40+
```
41+
42+
## Add packaging workflow (exercise)
43+
44+
You can try implement a simple sequential workflow that first builds macOS arm64 and then Windows x64 packages in `.github/workflows/package.yml`.
45+
46+
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`).
47+
48+
There is also a enhanced version that uses a matrix to build multiple Python versions and OSes in parallel in `solutions/package-matrix.yml`. You may check it out after finishing the exercise.
49+
50+
Steps:
51+
52+
1. Copy `solutions/package.yml` into `.github/workflows/package.yml`.
53+
2. Commit and push; this will trigger the workflow via `workflow_dispatch` if you run it manually, or on `push` tags.
54+
3. Check the workflow run and download artifacts from the run summary.

app/__init__.py

Whitespace-only changes.

app/hello.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def greet(name: str = "World") -> str:
2+
"""Return a friendly greeting."""
3+
return f"Hello, {name}!"
4+
5+
6+
if __name__ == "__main__":
7+
print(greet())

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest==7.4.2
2+
autopep8==2.1.2
3+
pyinstaller==5.13.0

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
max-line-length = 88
3+
4+
[tool:pytest]
5+
minversion = 7.0
6+
addopts = -ra -q
7+
python_files = test_*.py

solutions/package-exercise.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Simple Package — Sequential macOS arm64 & Windows x64
2+
3+
on:
4+
workflow_dispatch: # manual trigger
5+
push:
6+
tags: ["v*"]
7+
8+
jobs:
9+
build-macos-arm64:
10+
name: Build macOS arm64
11+
runs-on: macos-latest
12+
steps:
13+
- name: Check out
14+
uses: actions/checkout@v4
15+
16+
- name: Show runner arch
17+
run: uname -m || true
18+
- name: Setup Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.11"
22+
23+
# Exercise 1: Implement dependency installation here
24+
- name: Install deps
25+
run: |
26+
python -m pip install --upgrade pip
27+
echo "TODO: Achieve pip requirements installation over here"
28+
29+
# Remember to add a -n parameter to name the output binary appropriately for each platform
30+
- name: Build with PyInstaller (macOS arm64)
31+
run: |
32+
pyinstaller --onefile app/hello.py -n hello-macos-arm64
33+
- name: Debug dist
34+
run: ls -la dist || true
35+
- name: Upload macOS artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: hello-macos-arm64
39+
path: dist/hello-macos-arm64
40+
41+
build-windows-x64:
42+
name: Build Windows x64
43+
runs-on: windows-latest
44+
steps:
45+
- name: Check out
46+
uses: actions/checkout@v4
47+
- name: Setup Python
48+
uses: actions/setup-python@v4
49+
with:
50+
python-version: "3.11"
51+
52+
- name: Install deps
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -r requirements.txt
56+
57+
# Exercise 2: Implement Windows build steps here
58+
# You can refer to the macOS build steps above for guidance
59+
# - name: Build with PyInstaller (Windows x64)
60+
# ...
61+
62+
- name: Debug dist
63+
shell: pwsh
64+
run: dir dist || true
65+
66+
# Exercise 3: Implement artifact upload here
67+
# - name: Upload Windows artifact
68+
# uses: actions/upload-artifact@v4
69+
# with:
70+
# name: hello-windows-x64.exe
71+
# path: # TODO: Specify the path to the Windows build artifact here, it is a file with .exe extension

solutions/package-matrix.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Package — Build & Upload (Solution)
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags: ["v*"]
7+
8+
jobs:
9+
package:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
python-version: [3.10, 3.11]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
pip install pyinstaller
26+
- name: Build with PyInstaller
27+
run: |
28+
pyinstaller --onefile app/hello.py -n hello-${{ matrix.os }}-${{ matrix.python-version }}
29+
- name: Upload packaged artifact
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: hello-${{ matrix.os }}-${{ matrix.python-version }}
33+
path: dist/hello-${{ matrix.os }}-${{ matrix.python-version }}

0 commit comments

Comments
 (0)