Files
ratune-builder/scripts/build.sh
T
2026-10-26 22:54:24 +03:00

26 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
version="${1:?usage: build.sh VERSION TAG}"
tag="${2:?usage: build.sh VERSION TAG}"
[[ "$tag" == "v$version" ]] || { echo "Tag/version mismatch: $tag vs $version" >&2; exit 1; }
sed -i -E "s/^pkgver=.*/pkgver=${version}/; s/^pkgrel=.*/pkgrel=1/" PKGBUILD
# makepkg must not run as root. In Gitea's Arch container the job normally runs
# as root, so build as an unprivileged account and keep the workspace writable.
if [[ "$(id -u)" -eq 0 ]]; then
id builder >/dev/null 2>&1 || useradd --create-home --shell /bin/bash builder
chown -R builder:builder "$PWD"
runuser -u builder -- makepkg --syncdeps --cleanbuild --clean --noconfirm
# Restore ownership so later workflow steps can commit .current-version as the runner user.
chown -R "$(stat -c %u:%g .git 2>/dev/null || echo 0:0)" "$PWD" 2>/dev/null || chown -R root:root "$PWD"
else
makepkg --syncdeps --cleanbuild --clean --noconfirm
fi
pkg="$(find . -maxdepth 1 -type f -name 'ratune-*.pkg.tar.zst' -print -quit)"
[[ -n "$pkg" ]] || { echo "No package was produced" >&2; exit 1; }
printf '%s\n' "$pkg" > .package-path
echo "Built package: $pkg"