Skip to content

Commit fa3fd1e

Browse files
feat: optimized it more.
1 parent 204857c commit fa3fd1e

1 file changed

Lines changed: 48 additions & 22 deletions

File tree

.github/workflows/release-binaries.yml

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ jobs:
3333
run: |
3434
VERSION=${GITHUB_REF_NAME#v}
3535
SHA=$(git rev-parse --short HEAD)
36-
DEPS_HASH=$(shasum -a 256 pyproject.toml 2>/dev/null | cut -d' ' -f1 || echo "nodeps")
3736
38-
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
39-
echo "SHA=$SHA" >> $GITHUB_OUTPUT
40-
echo "DEPS=$DEPS_HASH" >> $GITHUB_OUTPUT
37+
# sha256sum on Linux, shasum on macOS — both unavailable on Windows
38+
# so we use Python for a cross-platform hash
39+
DEPS_HASH=$(python -c "
40+
import hashlib, pathlib
41+
p = pathlib.Path('pyproject.toml')
42+
print(hashlib.sha256(p.read_bytes()).hexdigest()[:16] if p.exists() else 'nodeps')
43+
")
44+
45+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
46+
echo "SHA=$SHA" >> $GITHUB_OUTPUT
47+
echo "DEPS=$DEPS_HASH" >> $GITHUB_OUTPUT
4148
echo "CACHE_KEY=${{ runner.os }}-$VERSION-$DEPS_HASH" >> $GITHUB_OUTPUT
4249
4350
- uses: actions/setup-python@v5
@@ -60,7 +67,9 @@ jobs:
6067
6168
- name: Install system deps (Linux)
6269
if: runner.os == 'Linux'
63-
run: sudo apt-get update && sudo apt-get install -y build-essential strip
70+
# build-essential already pulls in binutils (which provides strip).
71+
# Do NOT list "strip" — it is not a package name and will abort apt.
72+
run: sudo apt-get update && sudo apt-get install -y build-essential patchelf
6473

6574
- name: Install system deps (macOS)
6675
if: runner.os == 'macOS'
@@ -70,10 +79,10 @@ jobs:
7079
if: runner.os == 'Windows'
7180
uses: ilammy/msvc-dev-cmd@v1
7281

73-
- name: Install Python deps (locked build)
82+
- name: Install Python deps
7483
run: |
7584
python -m pip install -U pip wheel setuptools
76-
pip install nuitka[onefile]
85+
pip install nuitka
7786
pip install .
7887
7988
- name: Create entrypoint
@@ -85,11 +94,11 @@ jobs:
8594
main()
8695
EOF
8796
88-
- name: Nuitka parallel build (REAL speed boost)
97+
- name: Build with Nuitka
8998
shell: bash
9099
run: |
91100
python -m nuitka \
92-
--mode=onefile \
101+
--onefile \
93102
--lto=yes \
94103
--jobs=2 \
95104
--assume-yes-for-downloads \
@@ -110,21 +119,25 @@ jobs:
110119
--python-flag=no_asserts \
111120
--python-flag=no_docstrings \
112121
--python-flag=isolated \
113-
--onefile-tempdir-spec={CACHE_DIR}/bangen/${{ steps.meta.outputs.VERSION }} \
122+
"--onefile-tempdir-spec={CACHE_DIR}/bangen/${{ steps.meta.outputs.VERSION }}" \
114123
_entry.py
115124
116-
- name: Fingerprinted artifacts (immutable builds)
125+
- name: Stage fingerprinted artifact
117126
shell: bash
118127
run: |
119128
mkdir -p dist
120129
NAME="bangen-${{ matrix.name }}-${{ steps.meta.outputs.VERSION }}-${{ steps.meta.outputs.SHA }}"
121130
122131
if [[ "$RUNNER_OS" == "Linux" ]]; then
123132
mv build/bangen dist/$NAME
133+
# strip is provided by binutils (part of build-essential)
124134
strip dist/$NAME
125135
elif [[ "$RUNNER_OS" == "macOS" ]]; then
126136
mv build/bangen dist/$NAME
137+
# strip ships with Xcode Command Line Tools
138+
strip dist/$NAME
127139
else
140+
# Nuitka always appends .exe on Windows regardless of --output-filename
128141
mv build/bangen.exe dist/$NAME.exe
129142
fi
130143
@@ -138,20 +151,33 @@ jobs:
138151
runs-on: ubuntu-latest
139152

140153
steps:
154+
# Checkout is required so git log/describe have history to work with
155+
- uses: actions/checkout@v4
156+
with:
157+
fetch-depth: 0 # full history so git describe can find previous tags
158+
141159
- uses: actions/download-artifact@v4
142160
with:
143161
path: artifacts
162+
merge-multiple: true # flatten into artifacts/ instead of artifacts/<name>/
144163

145-
- name: Generate changelog (safe range)
164+
- name: Generate changelog
146165
id: changelog
147166
shell: bash
148167
run: |
149-
PREV=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
150-
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
151-
git log $PREV..HEAD --pretty=format:"- %s" >> $GITHUB_OUTPUT || true
152-
echo "EOF" >> $GITHUB_OUTPUT
153-
154-
- name: Create DRAFT release (approval pipeline)
168+
PREV=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
169+
{
170+
echo "CHANGELOG<<EOF"
171+
if [[ -n "$PREV" ]]; then
172+
git log "$PREV"..HEAD --pretty=format:"- %s"
173+
else
174+
git log --pretty=format:"- %s"
175+
fi
176+
echo ""
177+
echo "EOF"
178+
} >> $GITHUB_OUTPUT
179+
180+
- name: Create DRAFT release
155181
uses: softprops/action-gh-release@v2
156182
with:
157183
tag_name: ${{ github.ref_name }}
@@ -162,7 +188,7 @@ jobs:
162188
${{ steps.changelog.outputs.CHANGELOG }}
163189
164190
## 🧬 Build Info
165-
- Commit: ${{ github.sha }}
166-
- Parallel matrix build (Linux/macOS/Windows)
167-
- Nuitka LTO enabled
168-
files: artifacts/**/*
191+
- Commit: `${{ github.sha }}`
192+
- Matrix build: Linux · macOS · Windows
193+
- Nuitka LTO + onefile
194+
files: artifacts/*

0 commit comments

Comments
 (0)