Add package-first build and distribution workflow
This commit is contained in:
parent
4a69c3d333
commit
993f51712b
13 changed files with 462 additions and 52 deletions
44
scripts/package_arch.sh
Executable file
44
scripts/package_arch.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
source "${SCRIPT_DIR}/package_common.sh"
|
||||
|
||||
require_command git
|
||||
require_command sha256sum
|
||||
|
||||
VERSION="$(project_version)"
|
||||
PACKAGE_NAME="$(project_name)"
|
||||
ARCH_DIST_DIR="${DIST_DIR}/arch"
|
||||
TARBALL_NAME="${PACKAGE_NAME}-${VERSION}.tar.gz"
|
||||
TARBALL_PATH="${ARCH_DIST_DIR}/${TARBALL_NAME}"
|
||||
PKGBUILD_PATH="${ARCH_DIST_DIR}/PKGBUILD"
|
||||
|
||||
mkdir -p "${ARCH_DIST_DIR}"
|
||||
|
||||
git -C "${ROOT_DIR}" archive \
|
||||
--format=tar.gz \
|
||||
--prefix="${PACKAGE_NAME}-${VERSION}/" \
|
||||
HEAD \
|
||||
> "${TARBALL_PATH}"
|
||||
|
||||
TARBALL_SHA256="$(sha256sum "${TARBALL_PATH}" | awk '{print $1}')"
|
||||
|
||||
render_template \
|
||||
"${ROOT_DIR}/packaging/arch/PKGBUILD.in" \
|
||||
"${PKGBUILD_PATH}" \
|
||||
"VERSION=${VERSION}" \
|
||||
"TARBALL_NAME=${TARBALL_NAME}" \
|
||||
"TARBALL_SHA256=${TARBALL_SHA256}"
|
||||
|
||||
echo "generated ${PKGBUILD_PATH}"
|
||||
echo "generated ${TARBALL_PATH}"
|
||||
|
||||
if [[ "${BUILD_ARCH_PACKAGE:-0}" == "1" ]]; then
|
||||
require_command makepkg
|
||||
(
|
||||
cd "${ARCH_DIST_DIR}"
|
||||
makepkg -f
|
||||
)
|
||||
fi
|
||||
84
scripts/package_common.sh
Executable file
84
scripts/package_common.sh
Executable 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
|
||||
}
|
||||
64
scripts/package_deb.sh
Executable file
64
scripts/package_deb.sh
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
source "${SCRIPT_DIR}/package_common.sh"
|
||||
|
||||
require_command dpkg-deb
|
||||
require_command python3
|
||||
|
||||
VERSION="$(project_version)"
|
||||
PACKAGE_NAME="$(project_name)"
|
||||
ARCH="${DEB_ARCH:-}"
|
||||
if [[ -z "${ARCH}" ]]; then
|
||||
if command -v dpkg >/dev/null 2>&1; then
|
||||
ARCH="$(dpkg --print-architecture)"
|
||||
else
|
||||
ARCH="amd64"
|
||||
fi
|
||||
fi
|
||||
|
||||
build_wheel
|
||||
WHEEL_PATH="$(latest_wheel_path)"
|
||||
|
||||
STAGE_DIR="${BUILD_DIR}/deb/${PACKAGE_NAME}_${VERSION}_${ARCH}"
|
||||
PACKAGE_BASENAME="${PACKAGE_NAME}_${VERSION}_${ARCH}"
|
||||
DEB_PATH="${DIST_DIR}/${PACKAGE_BASENAME}.deb"
|
||||
VENV_DIR="${STAGE_DIR}/opt/${PACKAGE_NAME}/venv"
|
||||
PIP_ARGS=()
|
||||
if [[ -n "${AMAN_WHEELHOUSE_DIR:-}" ]]; then
|
||||
PIP_ARGS+=(--no-index --find-links "${AMAN_WHEELHOUSE_DIR}")
|
||||
fi
|
||||
|
||||
rm -rf "${STAGE_DIR}"
|
||||
mkdir -p "${STAGE_DIR}/DEBIAN"
|
||||
mkdir -p "${STAGE_DIR}/usr/bin"
|
||||
mkdir -p "${STAGE_DIR}/usr/lib/systemd/user"
|
||||
mkdir -p "${STAGE_DIR}/opt/${PACKAGE_NAME}"
|
||||
|
||||
render_template \
|
||||
"${ROOT_DIR}/packaging/deb/control.in" \
|
||||
"${STAGE_DIR}/DEBIAN/control" \
|
||||
"PACKAGE_NAME=${PACKAGE_NAME}" \
|
||||
"VERSION=${VERSION}" \
|
||||
"ARCH=${ARCH}"
|
||||
|
||||
cp "${ROOT_DIR}/packaging/deb/postinst" "${STAGE_DIR}/DEBIAN/postinst"
|
||||
chmod 0755 "${STAGE_DIR}/DEBIAN/postinst"
|
||||
|
||||
python3 -m venv --system-site-packages "${VENV_DIR}"
|
||||
"${VENV_DIR}/bin/python" -m pip install "${PIP_ARGS[@]}" "${WHEEL_PATH}"
|
||||
|
||||
cat >"${STAGE_DIR}/usr/bin/${PACKAGE_NAME}" <<EOF
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
exec /opt/${PACKAGE_NAME}/venv/bin/${PACKAGE_NAME} "\$@"
|
||||
EOF
|
||||
chmod 0755 "${STAGE_DIR}/usr/bin/${PACKAGE_NAME}"
|
||||
|
||||
cp "${ROOT_DIR}/systemd/aman.service" "${STAGE_DIR}/usr/lib/systemd/user/aman.service"
|
||||
|
||||
rm -f "${DEB_PATH}"
|
||||
dpkg-deb --build --root-owner-group "${STAGE_DIR}" "${DEB_PATH}"
|
||||
echo "built ${DEB_PATH}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue