name: Build and publish powerlevel10k

# Powerlevel10k (the BOS default zsh prompt) is AUR-only, so BOS maintains an
# in-house PKGBUILD and publishes the built package to the [breadway] repo.
# Builds gitstatus + libgit2 from source, so it needs cmake + zsh beyond base-devel.
on:
  push:
    paths:
      - 'packaging/powerlevel10k/**'
  workflow_dispatch:

jobs:
  powerlevel10k:
    runs-on: [self-hosted, hestia]
    container:
      image: archlinux:latest
    steps:
      - name: Build and publish
        env:
          PUBLISH_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
        run: |
          set -euo pipefail
          pacman -Syu --noconfirm base-devel git cmake zsh
          useradd -m builder
          git config --global --add safe.directory '*'
          git clone --depth 1 --branch "${GITHUB_REF_NAME}" \
            "https://git.breadway.dev/${GITHUB_REPOSITORY}.git" /home/builder/src
          chown -R builder:builder /home/builder/src
          su builder -c "cd /home/builder/src/packaging/powerlevel10k && makepkg -f --noconfirm --nocheck"
          PKG=$(find /home/builder/src/packaging/powerlevel10k -name '*.pkg.tar.zst' | head -1)
          curl -fsS -X PUT \
            -H "Authorization: token ${PUBLISH_TOKEN}" \
            -H "Content-Type: application/octet-stream" \
            --data-binary "@${PKG}" \
            "https://git.breadway.dev/api/packages/Breadway/arch/os"
