Skip to content

Commit 25c0895

Browse files
committed
feat: add release workflow, update docs
1 parent 78eb007 commit 25c0895

File tree

7 files changed

+123
-42
lines changed

7 files changed

+123
-42
lines changed

.github/workflows/package-matrix.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ env:
33
PIP_DISABLE_PIP_VERSION_CHECK: "1"
44

55
on:
6-
workflow_dispatch:
7-
push:
8-
tags: ["v*"]
6+
release:
7+
types: [published]
98

109
jobs:
1110
package:
@@ -16,6 +15,8 @@ jobs:
1615
python-version: [3.8, 3.11]
1716
steps:
1817
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
1920
- name: Set up Python
2021
uses: actions/setup-python@v4
2122
with:
@@ -33,3 +34,13 @@ jobs:
3334
with:
3435
name: hello-${{ matrix.os }}-${{ matrix.python-version }}
3536
path: dist/hello-${{ matrix.os }}-${{ matrix.python-version }}*
37+
38+
- name: Upload artifact to GitHub Release
39+
if: github.event_name == 'release'
40+
uses: softprops/action-gh-release@v1
41+
with:
42+
files: |
43+
dist/hello-${{ matrix.os }}-${{ matrix.python-version }}*
44+
tag_name: ${{ github.event.release.tag_name }}
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/package.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
steps:
1313
- name: Check out
1414
uses: actions/checkout@v4
15-
1615
- name: Show runner arch
1716
run: uname -m || true
1817
- name: Setup Python

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Create Release Tag
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Release version (e.g. 1.0.0)."
8+
required: true
9+
default: "1.0.0"
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
create-tag:
16+
name: Create and push tag
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Validate and normalize version input
26+
id: normalize
27+
run: |
28+
set -euo pipefail
29+
raw_version="${{ github.event.inputs.version }}"
30+
if [ -z "$raw_version" ]; then
31+
echo "No version provided. Use workflow_dispatch input 'version'." >&2
32+
exit 1
33+
fi
34+
# strip any leading 'v' or 'V'
35+
normalized=$(echo "$raw_version" | sed -E 's/^[vV]//')
36+
if [ -z "$normalized" ]; then
37+
echo "Provided version '$raw_version' is invalid after stripping leading 'v' — please supply a semantic version like 1.2.3." >&2
38+
exit 1
39+
fi
40+
# simple semver-like warning (not fully strict), continue even if it doesn't match
41+
if ! echo "$normalized" | grep -E -q '^[0-9]+(\.[0-9]+){1,2}([-.+][0-9A-Za-z.-]+)?$'; then
42+
echo "Warning: version '$normalized' doesn't look like semver (X.Y or X.Y.Z). Continuing anyway." >&2
43+
fi
44+
tag="v${normalized}"
45+
echo "Normalized version: $normalized"
46+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
47+
48+
- name: Confirm tag does not already exist
49+
run: |
50+
tag=${{ steps.normalize.outputs.tag }}
51+
echo "Checking if tag $tag exists on origin..."
52+
if git ls-remote --tags origin | grep -q "refs/tags/$tag"; then
53+
echo "Tag $tag already exists on origin — aborting to avoid overwriting." >&2
54+
exit 1
55+
fi
56+
57+
- name: Create annotated tag and push to origin
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
run: |
61+
tag=${{ steps.normalize.outputs.tag }}
62+
git config user.name "github-actions[bot]"
63+
git config user.email "github-actions[bot]@users.noreply.github.com"
64+
echo "Creating annotated tag $tag"
65+
git tag -a "$tag" -m "Release $tag"
66+
# Set remote URL that uses the token to push the new tag
67+
remote_url="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}"
68+
git remote set-url origin "$remote_url"
69+
git push origin "$tag"
70+
71+
- name: Create GitHub release for the tag
72+
uses: actions/create-release@v1
73+
with:
74+
tag_name: ${{ steps.normalize.outputs.tag }}
75+
release_name: "Release ${{ steps.normalize.outputs.tag }}"
76+
draft: false
77+
prerelease: false
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
13+
# Checkout the repository - Add this step at the beginning of the steps to help the Job access the code
14+
- name: Checkout Repo
15+
uses: actions/checkout@v4
16+
17+
# Set up Python environment - Automatically install Python for the job efficiently
1418
- name: Set up Python
1519
uses: actions/setup-python@v4
1620
with:
1721
python-version: "3.11"
22+
23+
# Install dependencies - Install the required packages for testing and linting
1824
- name: Install dependencies
1925
run: |
2026
python -m pip install --upgrade pip
2127
pip install -r requirements.txt
28+
29+
# Run linting - Check code style using autopep8
2230
- name: Run autopep8 check
2331
run: |
2432
pip install autopep8
2533
autopep8 --diff --recursive app tests
2634
35+
# Run tests - Execute the test suite using pytest. If everything passes, the job will succeed, else it will fail and report the issues
2736
- name: Run tests
2837
env:
2938
PYTHONPATH: ${{ github.workspace }}

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ls -la dist
3232
On Windows PowerShell:
3333

3434
```powershell
35-
py -3 -m venv .venv
35+
python -m venv .venv
3636
.\.venv\Scripts\Activate.ps1
3737
.venv\Scripts\pip.exe install -r requirements.txt
3838
.venv\Scripts\pyinstaller.exe --onefile app/hello.py
@@ -45,10 +45,28 @@ You can try implement a simple sequential workflow that first builds macOS arm64
4545

4646
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`).
4747

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.
48+
There is also a enhanced version that uses a matrix to build multiple Python versions and OSes in parallel in `.github/workflows/package-matrix.yml`. You may check it out after finishing the exercise.
4949

5050
Steps:
5151

5252
1. Copy `solutions/package.yml` into `.github/workflows/package.yml`.
5353
2. Commit and push; this will trigger the workflow via `workflow_dispatch` if you run it manually, or on `push` tags.
5454
3. Check the workflow run and download artifacts from the run summary.
55+
56+
## Release flow (automatic packaging and release assets)
57+
58+
The repository includes a pair of workflows to create a tag, publish a release, and attach build artifacts to the release:
59+
60+
- `release.yml` — creates a `vX.Y.Z` tag from the workflow_dispatch input and publishes a GitHub Release.
61+
- `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.
62+
63+
How it works:
64+
65+
1. Use the **Create Release** workflow in the Actions tab.
66+
2. The workflow will create the tag base on your input and publish the release; this publishes a `release` event.
67+
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.
68+
69+
Notes:
70+
71+
- The build artifacts are attached to the Release created by `release.yml`.
72+
- Packaging is also possible manually by running the `Package — Build & Upload using Matrix` workflow.
File renamed without changes.

solutions/package-matrix.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)