Skip to content

Commit 9bc2dc3

Browse files
Refactor GitHub Actions workflow for Bangen release
1 parent 32244a3 commit 9bc2dc3

1 file changed

Lines changed: 49 additions & 127 deletions

File tree

Lines changed: 49 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,116 @@
1-
name: Build Bangen (Nuitka)
1+
name: Build & Release Bangen
22

33
on:
4+
workflow_dispatch:
45
push:
56
tags:
6-
- "v*"
7-
workflow_dispatch:
7+
- "*.*.*"
88

9-
permissions:
10-
contents: write
9+
concurrency:
10+
group: release-${{ github.ref }}
11+
cancel-in-progress: true
1112

1213
jobs:
13-
# --- Tagging Job ---
14-
# Ensures a version tag exists based on pyproject.toml if triggered from a branch
15-
tag:
16-
if: github.ref_type == 'branch'
17-
runs-on: ubuntu-latest
18-
outputs:
19-
version: ${{ steps.version.outputs.VERSION }}
20-
steps:
21-
- uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
24-
25-
- name: Extract version
26-
id: version
27-
run: |
28-
VERSION=$(python - <<EOF
29-
import tomllib, pathlib
30-
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
31-
print(data["project"]["version"])
32-
EOF
33-
)
34-
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
35-
36-
- name: Create tag if missing
37-
run: |
38-
TAG_NAME="v${{ steps.version.outputs.VERSION }}"
39-
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
40-
echo "Tag $TAG_NAME already exists."
41-
else
42-
git config user.name "github-actions"
43-
git config user.email "github-actions@github.com"
44-
git tag "$TAG_NAME"
45-
git push origin "$TAG_NAME"
46-
fi
47-
48-
# --- Build Job ---
49-
# Compiles the application into a single executable for Linux, macOS, and Windows
5014
build:
51-
needs: tag
15+
name: Build (${{ matrix.name }})
16+
runs-on: ${{ matrix.os }}
17+
5218
strategy:
5319
fail-fast: false
5420
matrix:
5521
include:
5622
- os: ubuntu-latest
5723
name: linux
58-
- os: macos-latest
59-
name: macos
6024
- os: windows-latest
6125
name: windows
62-
runs-on: ${{ matrix.os }}
26+
- os: macos-latest
27+
name: macos
28+
6329
steps:
6430
- uses: actions/checkout@v4
6531

66-
- name: Extract Metadata & Validate
67-
id: meta
68-
shell: bash
69-
run: |
70-
PYPROJECT_VERSION=$(python - <<EOF
71-
import tomllib, pathlib
72-
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
73-
print(data["project"]["version"])
74-
EOF
75-
)
76-
77-
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
78-
VERSION=${GITHUB_REF_NAME#v}
79-
else
80-
VERSION=$PYPROJECT_VERSION
81-
fi
82-
83-
SHA=$(git rev-parse --short HEAD)
84-
DEPS_HASH=$(python - <<EOF
85-
import hashlib, pathlib
86-
p = pathlib.Path("pyproject.toml")
87-
print(hashlib.sha256(p.read_bytes()).hexdigest()[:16])
88-
EOF
89-
)
90-
91-
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
92-
echo "SHA=$SHA" >> $GITHUB_OUTPUT
93-
echo "CACHE_KEY=${{ runner.os }}-$VERSION-$DEPS_HASH" >> $GITHUB_OUTPUT
94-
95-
- name: Setup Python
96-
uses: actions/setup-python@v5
32+
- uses: actions/setup-python@v5
9733
with:
9834
python-version: "3.11"
99-
cache: "pip"
10035

101-
- name: Cache Nuitka
36+
- name: Cache pip
10237
uses: actions/cache@v4
10338
with:
10439
path: |
10540
~/.cache/pip
106-
~/.cache/Nuitka
107-
~/Library/Caches/Nuitka
108-
~\AppData\Local\Nuitka\Nuitka\Cache
109-
key: nuitka-${{ steps.meta.outputs.CACHE_KEY }}
110-
restore-keys: |
111-
nuitka-${{ runner.os }}-
112-
113-
- name: Install System Dependencies (Linux)
114-
if: runner.os == 'Linux'
115-
run: sudo apt-get update && sudo apt-get install -y build-essential patchelf
41+
~/AppData/Local/pip/Cache
42+
key: pip-${{ runner.os }}-${{ hashFiles('requirements*.txt') }}
43+
restore-keys: pip-${{ runner.os }}-
11644

117-
- name: Install System Dependencies (macOS)
118-
if: runner.os == 'macOS'
119-
run: xcode-select -p || xcode-select --install || true
45+
- name: Install system deps (Linux)
46+
if: runner.os == 'Linux'
47+
run: sudo apt-get update && sudo apt-get install -y patchelf
12048

121-
- name: MSVC Setup (Windows)
49+
- name: MSVC setup (Windows)
12250
if: runner.os == 'Windows'
12351
uses: ilammy/msvc-dev-cmd@v1
12452

125-
- name: Install Python Dependencies
53+
- name: Install Python deps
54+
shell: bash
12655
run: |
127-
python -m pip install -U pip wheel
128-
pip install "setuptools<72"
129-
pip install nuitka[onefile]
130-
pip install .
56+
python -m pip install -U pip wheel nuitka
57+
[[ -f requirements.txt ]] && pip install -r requirements.txt || true
13158
132-
- name: Create Entrypoint Script
59+
- name: Write entrypoint
13360
shell: bash
13461
run: |
135-
cat > _entry.py << 'EOF'
136-
from bangen.app import main
137-
if __name__ == "__main__":
138-
main()
139-
EOF
62+
printf 'from bangen.app import main\nif __name__ == "__main__":\n main()\n' > _entry.py
14063
14164
- name: Build with Nuitka
14265
shell: bash
14366
run: |
67+
JOBS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
14468
python -m nuitka \
14569
--onefile \
146-
--jobs=auto \
70+
--lto=thin \
71+
--jobs="$JOBS" \
14772
--assume-yes-for-downloads \
14873
--output-dir=build \
14974
--output-filename=bangen \
150-
--nofollow-import-to=tkinter \
151-
--nofollow-import-to=unittest \
152-
--nofollow-import-to=test \
153-
--python-flag=no_asserts \
154-
--python-flag=no_docstrings \
155-
--python-flag=isolated \
156-
--onefile-tempdir-spec="{TEMP}/bangen" \
157-
--plugin-enable=anti-bloat \
75+
--follow-imports \
76+
--nofollow-import-to=tkinter,unittest,test,distutils,setuptools,pkg_resources \
77+
--python-flag=no_asserts,no_docstrings,isolated \
78+
--onefile-tempdir-spec="{CACHE_DIR}/bangen/${{ github.ref_name }}" \
15879
_entry.py
15980
160-
- name: Stage Artifact
81+
- name: Package artifact
16182
shell: bash
16283
run: |
16384
mkdir -p dist
164-
NAME="bangen-${{ matrix.name }}-${{ steps.meta.outputs.VERSION }}-${{ steps.meta.outputs.SHA }}"
85+
NAME="bangen-${{ matrix.name }}-${{ github.ref_name }}"
16586
if [[ "$RUNNER_OS" == "Windows" ]]; then
166-
mv build/bangen.exe "dist/$NAME.exe"
87+
mv build/bangen.exe dist/"$NAME.exe"
88+
(cd dist && zip "$NAME.zip" "$NAME.exe" && rm "$NAME.exe")
16789
else
168-
mv build/bangen "dist/$NAME"
90+
mv build/bangen dist/"$NAME"
91+
(cd dist && tar -czf "$NAME.tar.gz" "$NAME" && rm "$NAME")
16992
fi
17093
171-
- name: Upload Artifact
172-
uses: actions/upload-artifact@v4
94+
- uses: actions/upload-artifact@v4
17395
with:
17496
name: ${{ matrix.name }}-build
17597
path: dist/*
17698

177-
# --- Release Job ---
178-
# Consolidates all builds and creates a draft GitHub Release
17999
release:
180-
needs: [tag, build]
100+
name: Publish Release
101+
needs: build
181102
runs-on: ubuntu-latest
103+
permissions:
104+
contents: write # required for action-gh-release to create releases
105+
182106
steps:
183107
- uses: actions/download-artifact@v4
184108
with:
185109
path: artifacts
186110
merge-multiple: true
187111

188-
- name: Create Draft Release
189-
uses: softprops/action-gh-release@v2
112+
- uses: softprops/action-gh-release@v2
190113
with:
191-
tag_name: v${{ needs.tag.outputs.version }}
192-
name: Bangen v${{ needs.tag.outputs.version }}
193-
draft: true
114+
tag_name: ${{ github.ref_name }}
115+
name: Bangen ${{ github.ref_name }}
194116
files: artifacts/*

0 commit comments

Comments
 (0)