Skip to content

Commit f0e0025

Browse files
committed
feat: enhance version retrieval and sanitization for macOS build scripts
1 parent 5c98ce7 commit f0e0025

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

scripts/build/build_macos.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,40 @@ if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1
2121
exit 1
2222
fi
2323

24+
# Get version: prefer GITHUB_REF_NAME (CI), then pyproject.toml, then git tag, then default
25+
if [ -n "${GITHUB_REF_NAME:-}" ]; then
26+
VERSION="${GITHUB_REF_NAME#v}"
27+
else
28+
# Use tomllib (Python 3.11) to read pyproject.toml
29+
VERSION=$(
30+
python3 - <<'PY'
31+
import tomllib, sys, subprocess
32+
try:
33+
with open("pyproject.toml", "rb") as f:
34+
cfg = tomllib.load(f)
35+
v = cfg.get("project", {}).get("version")
36+
if v:
37+
print(v)
38+
sys.exit(0)
39+
except Exception:
40+
pass
41+
# fallback to git tag
42+
try:
43+
tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"], stderr=subprocess.DEVNULL).decode().strip()
44+
print(tag.lstrip("v"))
45+
sys.exit(0)
46+
except Exception:
47+
print("0.0.0")
48+
PY
49+
)
50+
fi
51+
52+
# sanitize for filenames
53+
VERSION_SAFE="${VERSION//\//-}"
54+
VERSION_SAFE="${VERSION_SAFE// /-}"
55+
VERSION_SAFE="$(echo "$VERSION_SAFE" | tr -cd 'A-Za-z0-9._-')"
56+
57+
2458
# Install/upgrade build dependencies
2559
python3 -m pip install --upgrade pip setuptools wheel cython numpy pyinstaller
2660

scripts/build/create_macos_dmg.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,38 @@ echo "============================================"
88
echo "Creating macOS DMG Installer"
99
echo "============================================"
1010

11-
# Get version and architecture
11+
# Get version (prefer GITHUB_REF_NAME, then pyproject.toml, then git tag, then default)
1212
if [ -n "${GITHUB_REF_NAME:-}" ]; then
1313
VERSION="${GITHUB_REF_NAME#v}"
1414
else
15-
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "3.0.4")
15+
VERSION=$(
16+
python3 - <<'PY'
17+
import sys, subprocess
18+
try:
19+
import tomllib
20+
with open("pyproject.toml","rb") as f:
21+
cfg = tomllib.load(f)
22+
v = cfg.get("project",{}).get("version")
23+
if v:
24+
print(v); sys.exit(0)
25+
except Exception:
26+
pass
27+
try:
28+
tag = subprocess.check_output(["git","describe","--tags","--abbrev=0"], stderr=subprocess.DEVNULL).decode().strip()
29+
print(tag.lstrip("v")); sys.exit(0)
30+
except Exception:
31+
print("3.0.4")
32+
PY
33+
)
1634
fi
1735

36+
# sanitize VERSION for filenames
37+
VERSION_SAFE="${VERSION//\//-}"
38+
VERSION_SAFE="${VERSION_SAFE// /-}"
39+
VERSION_SAFE="$(echo "$VERSION_SAFE" | tr -cd 'A-Za-z0-9._-')"
40+
1841
ARCH=$(uname -m)
19-
echo "Version: ${VERSION}"
42+
echo "Version: ${VERSION} (safe: ${VERSION_SAFE})"
2043
echo "Architecture: ${ARCH}"
2144

2245
# Verify single-file executable exists
@@ -82,7 +105,7 @@ if [ -f "LICENSE" ]; then
82105
fi
83106

84107
# Create DMG
85-
DMG_NAME="pyprophet-${VERSION}-macos-${ARCH}.dmg"
108+
DMG_NAME="pyprophet-${VERSION_SAFE}-macos-${ARCH}.dmg"
86109
echo "Creating DMG: ${DMG_NAME}"
87110

88111
# Remove any existing DMG

0 commit comments

Comments
 (0)