| 1 | #!/usr/bin/env bash |
| 2 | # Build an Arch .pkg.tar.zst with makepkg. The package is not installed and |
| 3 | # it is not published. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 7 | if ! command -v makepkg >/dev/null 2>&1; then |
| 8 | echo "makepkg is not installed. The Arch package job runs on archlinux/archlinux:base-devel." >&2 |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | version="$(bash "$root/scripts/ci/package-version.sh")" |
| 13 | export REPO_ROOT="$root" |
| 14 | export PAPERDOLL_PKGVER="$version" |
| 15 | export CARGO_HOME="${CARGO_HOME:-$root/cargo-home}" |
| 16 | |
| 17 | work="$(mktemp -d)" |
| 18 | trap 'rm -rf "$work"' EXIT |
| 19 | cp "$root/packaging/arch/PKGBUILD" "$work/PKGBUILD" |
| 20 | |
| 21 | run_makepkg() { |
| 22 | (cd "$work" && makepkg -f --noconfirm --nodeps) |
| 23 | } |
| 24 | |
| 25 | if [[ "$(id -u)" -eq 0 ]]; then |
| 26 | if ! id builduser >/dev/null 2>&1; then |
| 27 | useradd -m builduser |
| 28 | fi |
| 29 | chown -R builduser:builduser "$root" "$work" |
| 30 | su builduser -c "export REPO_ROOT='$root' PAPERDOLL_PKGVER='$version' CARGO_HOME='$CARGO_HOME' PATH='$PATH'; cd '$work' && makepkg -f --noconfirm --nodeps" |
| 31 | else |
| 32 | run_makepkg |
| 33 | fi |
| 34 | |
| 35 | mapfile -t packages < <(find "$work" -maxdepth 1 -type f -name "paperdoll-renderer-${version}-*-x86_64.pkg.tar.zst" ! -name '*.sig') |
| 36 | if [[ "${#packages[@]}" -ne 1 ]]; then |
| 37 | echo "expected one Arch package, found ${#packages[@]}" >&2 |
| 38 | exit 1 |
| 39 | fi |
| 40 | mkdir -p "$root/dist" |
| 41 | cp -f "${packages[0]}" "$root/dist/paperdoll-renderer-x86_64.pkg.tar.zst" |
| 42 | echo "wrote dist/paperdoll-renderer-x86_64.pkg.tar.zst" |