feat(release): build Arch Linux package (.pkg.tar.zst) natively via makepkg from release tarball (#16)

* feat(release): build Arch Linux package (.pkg.tar.zst) via makepkg from release tarball

* fix(arch-package): fix PKGBUILD provides quotes, add podman fallback and e2e test
This commit is contained in:
Dylan M. Taylor authored and GitHub committed 2026-10-18 00:37:20 -04:00
1 parent 43f4e83c68
commit 31e08e5e14
7 files changed
+438 -1

No files matched your search

+41 -1
View File
@@ -41,6 +41,11 @@ on:
type: boolean
required: false
default: true
has-arch:
description: "Whether to build the Arch Linux package (.pkg.tar.zst) via makepkg"
type: boolean
required: false
default: true
wix-version:
description: "Version of WiX tool to install"
type: string
@@ -556,6 +561,41 @@ jobs:
path: dist/release/*.flatpak
if-no-files-found: error
arch:
name: Arch Linux ${{ matrix.arch }}
if: inputs.has-arch
needs: [version, linux]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
arch: [x86_64, aarch64]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: release-linux-${{ matrix.arch }}
path: dist/linux
- name: Find the release tarball
id: tarball
run: |
shopt -s nullglob
tarballs=(dist/linux/*-linux-${{ matrix.arch }}.tar.gz)
if [ "${#tarballs[@]}" -ne 1 ]; then
echo "::error::expected one tarball in release-linux-${{ matrix.arch }}, found ${#tarballs[@]}"
exit 1
fi
echo "path=${tarballs[0]}" >>"$GITHUB_OUTPUT"
- uses: storytold/craft-common-actions/actions/arch-package@main
with:
tarball: ${{ steps.tarball.outputs.path }}
arch: ${{ matrix.arch }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-arch-${{ matrix.arch }}
path: dist/release/*.pkg.tar.zst
if-no-files-found: error
freebsd:
name: FreeBSD x86_64
if: inputs.has-freebsd
@@ -907,7 +947,7 @@ jobs:
timeout-minutes: 10
name: Draft GitHub Release
if: "!cancelled() && !contains(needs.*.result, 'failure')"
needs: [version, macos, windows, linux, linux-riscv64, flatpak, freebsd, web, server]
needs: [version, macos, windows, linux, linux-riscv64, flatpak, arch, freebsd, web, server]
runs-on: ubuntu-latest
environment: release
permissions:
+3
View File
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
dist/
+1
View File
@@ -12,6 +12,7 @@ Full multi-platform release pipeline for Craft apps:
- **Windows** (x64, x86, ARM64 MSI installer with WiX v5, CLI, Azure Trusted Signing)
- **Linux** (x86_64, aarch64 AppImage, deb, rpm, tar.gz via nfpm)
- **Flatpak** (x86_64, aarch64 bundle generation)
- **Arch Linux** (x86_64, aarch64 `.pkg.tar.zst` built via `makepkg` from release tarball, named by bundle id; set `has-arch: false` to skip)
- **FreeBSD** (FreeBSD 15.1-STABLE VM build & packaging)
- **WebAssembly** (wasm32-unknown-unknown with Trunk)
- **Linux RISC-V 64** (cross-compilation for riscv64gc-unknown-linux-gnu, producing deb, rpm, and tar.gz via SHA256-verified nfpm)
+62
View File
@@ -0,0 +1,62 @@
name: "Arch Linux package"
description: "Builds an Arch Linux package (.pkg.tar.zst) from a Craft app's release tarball using makepkg"
inputs:
tarball:
description: "Path to the release tarball (<app>-<version>-linux-<arch>.tar.gz)"
required: true
arch:
description: "Target architecture (x86_64 or aarch64)"
required: false
default: "x86_64"
output-dir:
description: "Directory the .pkg.tar.zst is written to"
required: false
default: "dist/release"
license:
description: "SPDX license expression for the package"
required: false
default: "MIT OR Apache-2.0"
pkgrel:
description: "Package release number"
required: false
default: "1"
runs:
using: "composite"
steps:
- name: Build the Arch package with makepkg
shell: bash
env:
TARBALL: ${{ inputs.tarball }}
TARGET_ARCH: ${{ inputs.arch }}
OUTPUT_DIR: ${{ inputs.output-dir }}
ARCH_LICENSE: ${{ inputs.license }}
PKGREL: ${{ inputs.pkgrel }}
run: |
if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then
SOURCE_DATE_EPOCH="$(git log -1 --format=%ct 2>/dev/null || date +%s)"
fi
export SOURCE_DATE_EPOCH
if command -v makepkg >/dev/null; then
"$GITHUB_ACTION_PATH/arch-package.sh" "$TARBALL" "$TARGET_ARCH" "$OUTPUT_DIR"
elif command -v docker >/dev/null || command -v podman >/dev/null; then
CONTAINER_CLI="$(command -v docker || command -v podman)"
"$CONTAINER_CLI" run --rm \
--tmpfs /tmp \
-e TARBALL="$TARBALL" \
-e TARGET_ARCH="$TARGET_ARCH" \
-e OUTPUT_DIR="$OUTPUT_DIR" \
-e ARCH_LICENSE="$ARCH_LICENSE" \
-e PKGREL="$PKGREL" \
-e SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" \
-v "$GITHUB_WORKSPACE:/workspace" \
-v "$GITHUB_ACTION_PATH:/action:ro" \
-w /workspace \
archlinux:base-devel \
bash /action/docker-entrypoint.sh
else
echo "::error::Neither makepkg nor a container runtime (docker/podman) was found to build the Arch package"
exit 1
fi
+200
View File
@@ -0,0 +1,200 @@
#!/usr/bin/env bash
# Builds an Arch Linux package (.pkg.tar.zst) from a Craft app's release tarball using makepkg.
#
# Usage: arch-package.sh <tarball> [<arch>] [<output dir>]
# writes <output dir>/<app>-<version>-linux-<arch>.pkg.tar.zst (default output dir: dist/release)
#
# Env: ARCH_LICENSE SPDX license expression (default: MIT OR Apache-2.0)
# PKGREL Package release number (default: 1)
# SOURCE_DATE_EPOCH timestamp for builddate and package reproducibility (default: now)
set -euo pipefail
tarball="${1:?usage: arch-package.sh <tarball> [<arch>] [<output dir>]}"
target_arch="${2:-${TARGET_ARCH:-x86_64}}"
out_dir="${3:-${OUTPUT_DIR:-dist/release}}"
license="${ARCH_LICENSE:-MIT OR Apache-2.0}"
pkgrel="${PKGREL:-1}"
epoch="${SOURCE_DATE_EPOCH:-$(date +%s)}"
die() { echo "error: $*" >&2; exit 1; }
[ -f "$tarball" ] || die "$tarball not found"
for tool in makepkg bsdtar zstd tar; do
command -v "$tool" >/dev/null || die "$tool not found"
done
case "$target_arch" in
x86_64) arch=x86_64 ;;
aarch64|arm64) arch=aarch64 ;;
riscv64) arch=riscv64 ;;
*) arch="$target_arch" ;;
esac
work="$(mktemp -d /tmp/arch-build.XXXXXX)"
trap 'rm -rf "$work"' EXIT
stage="$work/stage"
mkdir -p "$stage"
# Extract the tarball
tar -xzf "$tarball" -C "$stage"
# If the archive wrapped the files in a single root directory, flatten it
shopt -s nullglob
subdirs=("$stage"/*)
shopt -u nullglob
if [ "${#subdirs[@]}" -eq 1 ] && [ -d "${subdirs[0]}" ]; then
if [ -d "${subdirs[0]}/bin" ] || [ -d "${subdirs[0]}/share" ]; then
shopt -s dotglob
mv "${subdirs[0]}"/* "$stage/"
shopt -u dotglob
rmdir "${subdirs[0]}"
fi
fi
# Detect application name and version
tar_basename="$(basename "$tarball" .tar.gz)"
if [[ "$tar_basename" =~ ^([a-zA-Z0-9_-]+)-([0-9]+\.[0-9]+\.[0-9]+[^-_]*)-linux-([a-zA-Z0-9_]+)$ ]]; then
app="${BASH_REMATCH[1]}"
raw_version="${BASH_REMATCH[2]}"
else
shopt -s nullglob
bins=("$stage"/bin/*)
shopt -u nullglob
[ "${#bins[@]}" -gt 0 ] || die "no executables found in $tarball"
app="$(basename "${bins[0]}")"
app="${app%-cli}"
raw_version="0.0.0"
fi
# Format Arch pkgver (no hyphens or tildes allowed in pkgver)
upstream="${raw_version%-*}"
if [ "$upstream" != "$raw_version" ]; then
rel="${raw_version##*-}"
if [[ "$rel" =~ ^[0-9]+$ ]]; then
pkgrel="$rel"
fi
fi
pkgver="${upstream//\~/}"
pkgver="${pkgver//-/}"
# Determine package name from .desktop file (bundle id)
shopt -s nullglob
desktops=("$stage"/share/applications/*.desktop)
shopt -u nullglob
if [ "${#desktops[@]}" -gt 0 ]; then
pkgname="$(basename "${desktops[0]}" .desktop)"
else
pkgname="ai.storyteller.$app"
fi
# Determine description from AppStream metainfo if available
pkgdesc=""
shopt -s nullglob
metainfos=("$stage"/share/metainfo/*.metainfo.xml)
shopt -u nullglob
if [ "${#metainfos[@]}" -gt 0 ]; then
pkgdesc="$(sed -n 's:.*<summary>\(.*\)</summary>.*:\1:p' "${metainfos[0]}" 2>/dev/null | head -n 1 |
sed -e 's/&lt;/</g' -e 's/&gt;/>/g' -e 's/&quot;/"/g' -e "s/&apos;/'/g" -e 's/&amp;/\&/g')"
fi
if [ -z "$pkgdesc" ]; then
pkgdesc="$app"
fi
# Determine homepage url from AppStream metainfo if available
url="https://storyteller.ai"
if [ "${#metainfos[@]}" -gt 0 ]; then
metainfo_url="$(sed -n 's:.*<url type="homepage">\(.*\)</url>.*:\1:p' "${metainfos[0]}" 2>/dev/null | head -n 1)"
if [ -n "$metainfo_url" ]; then url="$metainfo_url"; fi
fi
# Format SPDX license expression into Arch license array
license_formatted=()
IFS='|' read -ra parts <<< "$(sed -E 's/ (OR|AND) /|/g' <<< "$license")"
for part in "${parts[@]}"; do
part="$(echo "$part" | xargs)"
[ -n "$part" ] && license_formatted+=("'$part'")
done
license_str="${license_formatted[*]}"
# Create makepkg.conf override
cat > "$work/makepkg.conf" <<EOF
if [ -f /etc/makepkg.conf ]; then
source /etc/makepkg.conf
fi
CARCH="$arch"
CHOST="${arch}-unknown-linux-gnu"
PKGEXT='.pkg.tar.zst'
COMPRESSZST=(zstd -c -T0 --ultra -20 -)
EOF
# Write PKGBUILD
cat > "$work/PKGBUILD" <<EOF
# Maintainer: Storyteller Authors
pkgname='$pkgname'
pkgver='$pkgver'
pkgrel='$pkgrel'
pkgdesc=$(printf '%q' "$pkgdesc")
arch=('$arch')
url=$(printf '%q' "$url")
license=($license_str)
depends=('glibc' 'gcc-libs' 'hicolor-icon-theme' 'libxkbcommon' 'vulkan-icd-loader')
optdepends=(
'alsa-lib: sound support'
'pipewire-alsa: audio playback and recording via PipeWire'
'pulseaudio: audio playback and recording via PulseAudio'
'wayland: native Wayland display support'
'libx11: X11 and XWayland display support'
'libxcursor: X11 cursor handling'
'libxi: X11 input handling'
'libxrandr: X11 display resolution handling'
'libglvnd: GPU rendering through EGL'
'mesa: GPU rendering through EGL'
'vulkan-driver: GPU rendering through Vulkan'
'xdg-desktop-portal: native desktop integration and file dialogs'
'cups: printing support'
)
provides=("$app=\$pkgver-\$pkgrel")
conflicts=('$app' '$app-bin' '$app-git')
options=('!strip' '!debug')
package() {
mkdir -p "\$pkgdir/usr"
if [ -d "$stage/bin" ]; then
cp -dr --no-preserve=ownership "$stage/bin" "\$pkgdir/usr/"
fi
if [ -d "$stage/share" ]; then
cp -dr --no-preserve=ownership "$stage/share" "\$pkgdir/usr/"
fi
find "\$pkgdir/usr" -type d -exec chmod 0755 {} +
find "\$pkgdir/usr" -type f -perm /111 -exec chmod 0755 {} +
find "\$pkgdir/usr" -type f ! -perm /111 -exec chmod 0644 {} +
local lic_dir="\$pkgdir/usr/share/licenses/\$pkgname"
mkdir -p "\$lic_dir"
if [ -d "\$pkgdir/usr/share/doc" ]; then
find "\$pkgdir/usr/share/doc" -maxdepth 2 -type f \( -iname "*license*" -o -iname "*notice*" -o -iname "*copying*" \) -exec cp -t "\$lic_dir" {} + 2>/dev/null || true
fi
}
EOF
echo "==> Building Arch package $pkgname-$pkgver-$pkgrel for $arch with makepkg..."
(cd "$work" && SOURCE_DATE_EPOCH="$epoch" makepkg --config "$work/makepkg.conf" --nodeps --clean --force)
shopt -s nullglob
built_pkgs=("$work"/*.pkg.tar.zst)
shopt -u nullglob
[ "${#built_pkgs[@]}" -eq 1 ] || die "expected 1 built package, found ${#built_pkgs[@]}"
pkg_file="${built_pkgs[0]}"
if command -v namcap >/dev/null; then
echo "==> Validating package with namcap:"
namcap "$pkg_file" || true
fi
mkdir -p "$out_dir"
target="$out_dir/$app-$raw_version-linux-$arch.pkg.tar.zst"
cp -f "$pkg_file" "$target"
echo "==> Wrote $target ($pkgname $pkgver-$pkgrel, $arch)"
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
# Ensure an unprivileged user exists because makepkg refuses to run as root
if ! id -u builder &>/dev/null; then
useradd -m -s /bin/bash builder
fi
out_dir="${OUTPUT_DIR:-dist/release}"
mkdir -p "$out_dir"
chmod 777 "$out_dir"
# Run arch-package.sh as builder user
su - builder -c "
export TARBALL='$TARBALL'
export TARGET_ARCH='$TARGET_ARCH'
export OUTPUT_DIR='$OUTPUT_DIR'
export ARCH_LICENSE='$ARCH_LICENSE'
export PKGREL='$PKGREL'
export SOURCE_DATE_EPOCH='$SOURCE_DATE_EPOCH'
cd '$PWD'
bash /action/arch-package.sh \"\$TARBALL\" \"\$TARGET_ARCH\" \"\$OUTPUT_DIR\"
"
# Ensure output packages are readable by the host user
chmod 0644 "$out_dir"/*.pkg.tar.zst 2>/dev/null || true
+105
View File
@@ -0,0 +1,105 @@
"""Unit tests for Arch Linux packaging action and workflow integration."""
import os
from pathlib import Path
import re
import shutil
import subprocess
import tarfile
import tempfile
import unittest
import yaml
ROOT = Path(__file__).resolve().parents[1]
RELEASE_WORKFLOW = ROOT / ".github/workflows/release.yml"
ACTION_YML = ROOT / "actions/arch-package/action.yml"
ARCH_SCRIPT = ROOT / "actions/arch-package/arch-package.sh"
class ArchWorkflowTests(unittest.TestCase):
def setUp(self):
self.data = yaml.load(RELEASE_WORKFLOW.read_text(), Loader=yaml.BaseLoader)
def test_has_arch_input_defined(self):
inputs = self.data["on"]["workflow_call"]["inputs"]
self.assertIn("has-arch", inputs)
self.assertEqual(inputs["has-arch"]["type"], "boolean")
self.assertEqual(inputs["has-arch"]["default"], "true")
def test_arch_job_structure(self):
jobs = self.data["jobs"]
self.assertIn("arch", jobs)
arch_job = jobs["arch"]
self.assertEqual(arch_job["if"], "inputs.has-arch")
self.assertEqual(arch_job["needs"], ["version", "linux"])
self.assertEqual(arch_job["runs-on"], "ubuntu-24.04")
self.assertEqual(arch_job["strategy"]["matrix"]["arch"], ["x86_64", "aarch64"])
def test_release_job_needs_arch(self):
release_job = self.data["jobs"]["release"]
self.assertIn("arch", release_job["needs"])
class ArchActionTests(unittest.TestCase):
def setUp(self):
self.action_data = yaml.safe_load(ACTION_YML.read_text())
def test_action_inputs(self):
inputs = self.action_data["inputs"]
self.assertIn("tarball", inputs)
self.assertTrue(inputs["tarball"]["required"])
self.assertIn("arch", inputs)
self.assertIn("output-dir", inputs)
self.assertIn("license", inputs)
def test_arch_script_syntax(self):
self.assertTrue(ARCH_SCRIPT.exists())
self.assertTrue(os.access(ARCH_SCRIPT, os.X_OK))
res = subprocess.run(["bash", "-n", str(ARCH_SCRIPT)], capture_output=True, text=True)
self.assertEqual(res.returncode, 0, f"Syntax error: {res.stderr}")
def test_arch_script_requires_tarball(self):
res = subprocess.run([str(ARCH_SCRIPT)], capture_output=True, text=True)
self.assertNotEqual(res.returncode, 0)
self.assertIn("usage", res.stderr)
def test_arch_script_missing_tarball(self):
res = subprocess.run([str(ARCH_SCRIPT), "/nonexistent.tar.gz"], capture_output=True, text=True)
self.assertNotEqual(res.returncode, 0)
self.assertIn("not found", res.stderr)
@unittest.skipUnless(
shutil.which("makepkg") and shutil.which("bsdtar") and shutil.which("zstd"),
"makepkg/bsdtar/zstd not installed",
)
def test_arch_package_build_end_to_end(self):
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
tar_root = tmp_path / "myapp-1.2.3-linux-x86_64"
(tar_root / "bin").mkdir(parents=True)
(tar_root / "share/applications").mkdir(parents=True)
(tar_root / "bin/myapp").write_text("#!/bin/sh\necho hello\n")
os.chmod(tar_root / "bin/myapp", 0o755)
(tar_root / "share/applications/com.example.myapp.desktop").write_text(
"[Desktop Entry]\nName=MyApp\nExec=myapp\nType=Application\n"
)
tarball = tmp_path / "myapp-1.2.3-linux-x86_64.tar.gz"
with tarfile.open(tarball, "w:gz") as tar:
tar.add(tar_root, arcname=tar_root.name)
out_dir = tmp_path / "dist"
res = subprocess.run(
[str(ARCH_SCRIPT), str(tarball), "x86_64", str(out_dir)],
capture_output=True,
text=True,
env={**os.environ, "ARCH_LICENSE": "MIT", "PKGREL": "1"},
)
self.assertEqual(res.returncode, 0, f"arch-package.sh failed: {res.stderr}\n{res.stdout}")
pkg_file = out_dir / "myapp-1.2.3-linux-x86_64.pkg.tar.zst"
self.assertTrue(pkg_file.exists())
if __name__ == "__main__":
unittest.main()