Add package-first build and distribution workflow

This commit is contained in:
Thales Maciel 2026-02-27 15:06:57 -03:00
parent 4a69c3d333
commit 993f51712b
13 changed files with 462 additions and 52 deletions

84
scripts/package_common.sh Executable file
View file

@ -0,0 +1,84 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
DIST_DIR="${ROOT_DIR}/dist"
BUILD_DIR="${ROOT_DIR}/build"
APP_NAME="aman"
mkdir -p "${DIST_DIR}" "${BUILD_DIR}"
require_command() {
local cmd="$1"
if command -v "${cmd}" >/dev/null 2>&1; then
return
fi
echo "missing required command: ${cmd}" >&2
exit 1
}
project_version() {
require_command python3
python3 - <<'PY'
from pathlib import Path
import re
text = Path("pyproject.toml").read_text(encoding="utf-8")
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"\s*$', text)
if not match:
raise SystemExit("project version not found in pyproject.toml")
print(match.group(1))
PY
}
project_name() {
require_command python3
python3 - <<'PY'
from pathlib import Path
import re
text = Path("pyproject.toml").read_text(encoding="utf-8")
match = re.search(r'(?m)^name\s*=\s*"([^"]+)"\s*$', text)
if not match:
raise SystemExit("project name not found in pyproject.toml")
print(match.group(1))
PY
}
build_wheel() {
require_command python3
python3 -m build --wheel --no-isolation
}
latest_wheel_path() {
require_command python3
python3 - <<'PY'
from pathlib import Path
import re
text = Path("pyproject.toml").read_text(encoding="utf-8")
name_match = re.search(r'(?m)^name\s*=\s*"([^"]+)"\s*$', text)
version_match = re.search(r'(?m)^version\s*=\s*"([^"]+)"\s*$', text)
if not name_match or not version_match:
raise SystemExit("project metadata not found in pyproject.toml")
name = name_match.group(1).replace("-", "_")
version = version_match.group(1)
candidates = sorted(Path("dist").glob(f"{name}-{version}-*.whl"))
if not candidates:
raise SystemExit("no wheel artifact found in dist/")
print(candidates[-1])
PY
}
render_template() {
local template_path="$1"
local output_path="$2"
shift 2
cp "${template_path}" "${output_path}"
for mapping in "$@"; do
local key="${mapping%%=*}"
local value="${mapping#*=}"
sed -i "s|__${key}__|${value}|g" "${output_path}"
done
}