moonarch-pkgbuilds/.gitea/workflows/build-and-publish.yaml
nevaforget 41a22d6281 fix(ci): fail hard when registry upload returns non-2xx
curl -sf was silencing upload errors: r105 was 'Published' six times
in a row but never landed in the registry. Capture the HTTP status
and abort on non-2xx so the run goes red and the response body shows
up in the log.
2026-04-20 12:47:26 +02:00

106 lines
4.2 KiB
YAML

# ABOUTME: Builds changed packages and publishes them to Gitea Package Registry.
# ABOUTME: Triggered by pkgver-bot commits (from per-project CI workflows).
name: Build and publish packages
on:
push:
branches:
- main
paths:
- '*/PKGBUILD'
jobs:
build-and-publish:
runs-on: moonarch
steps:
- name: Build and publish changed packages
run: |
rm -rf repo
git clone http://gitea:3000/nevaforget/moonarch-pkgbuilds.git repo
cd repo
CHANGED=$(git diff --name-only HEAD~1 HEAD | grep '/PKGBUILD$' | sed 's|/PKGBUILD||' || true)
if [ -z "$CHANGED" ]; then
echo "No PKGBUILD changes detected"
exit 0
fi
echo "Changed packages: $CHANGED"
# Sync pacman DB so makepkg -s can resolve current deps.
# NEVER change this to -Syu. The runner shares I/O with the host
# (act_runner runs in network-host mode on the Gitea server). A full
# system upgrade here took the host down on 2026-04-20 and required
# a hard reboot + Contabo abuse-block recovery. -Sy syncs the DB
# only; -s picks targeted makedepends via pacman.
sudo pacman -Sy --noconfirm
for pkg in $CHANGED; do
echo "==> Building $pkg"
cd "$pkg"
# Install makedepends manually (cargo, go, …) and skip the full
# depends check via -d. Rationale: moonarch-git's runtime depends
# include AUR-only packages (stasis, auto-cpufreq, ttf-ubuntusans-nerd)
# which pacman can't resolve. Those deps aren't needed at build time.
# Source the PKGBUILD in a subshell to read the array robustly —
# awk/grep parsing breaks on single-line vs multi-line formats.
MAKEDEPS=$(bash -c 'source ./PKGBUILD 2>/dev/null; printf "%s " "${makedepends[@]}"')
if [ -n "${MAKEDEPS// }" ]; then
# shellcheck disable=SC2086
sudo pacman -S --needed --noconfirm $MAKEDEPS
fi
makepkg -sfd --noconfirm
# makepkg can emit multiple artifacts per build (main + -debug
# split package). Upload each. Arch filename convention:
# <pkgname>-<pkgver>-<pkgrel>-<arch>.pkg.tar.zst; pkgver never
# contains '-', so we can strip from the right.
shopt -s nullglob
PKG_FILES=(*.pkg.tar.zst)
shopt -u nullglob
if [ "${#PKG_FILES[@]}" -eq 0 ]; then
echo "ERROR: No package file found for $pkg"
cd ..
continue
fi
for PKG_FILE in "${PKG_FILES[@]}"; do
base="${PKG_FILE%.pkg.tar.zst}"
PKG_ARCH="${base##*-}"
base="${base%-*}"
PKG_REL="${base##*-}"
base="${base%-*}"
PKG_VER="${base##*-}"
PKG_NAME="${base%-*}"
FULL_VER="${PKG_VER}-${PKG_REL}"
echo "==> Uploading $PKG_FILE ($PKG_NAME $FULL_VER $PKG_ARCH)"
# Delete old version if it exists (ignore 404)
curl -s -o /dev/null -X DELETE \
-H "Authorization: token ${{ secrets.PKG_REGISTRY_TOKEN }}" \
"https://gitea.moonarch.de/api/packages/nevaforget/arch/moonarch/${PKG_NAME}/${FULL_VER}/${PKG_ARCH}" || true
# Upload new version. Capture HTTP status — curl -sf alone
# hides the response, and a silent failure lets the run green
# while the registry stays stale.
HTTP_CODE=$(curl -s -w '%{http_code}' -o /tmp/upload.log \
-H "Authorization: token ${{ secrets.PKG_REGISTRY_TOKEN }}" \
--upload-file "$PKG_FILE" \
"https://gitea.moonarch.de/api/packages/nevaforget/arch/moonarch")
if [[ ! "$HTTP_CODE" =~ ^2 ]]; then
echo "ERROR: Upload failed with HTTP $HTTP_CODE for $PKG_FILE"
echo "--- server response ---"
cat /tmp/upload.log
echo "-----------------------"
exit 1
fi
echo "==> Published $PKG_NAME $FULL_VER (HTTP $HTTP_CODE)"
done
cd ..
done