# Maintainer: hyperpolymath
# Arch Linux PKGBUILD for echidnabot

pkgname=echidnabot
pkgver=0.1.0
pkgrel=1
pkgdesc="Proof-aware CI bot that orchestrates ECHIDNA for theorem proof verification"
arch=('x86_64' 'aarch64')
url="https://github.com/hyperpolymath/echidnabot"
license=('MPL-2.0')
depends=('gcc-libs' 'openssl')
makedepends=('rust' 'cargo' 'pkg-config')
optdepends=(
    'postgresql: For PostgreSQL backend'
    'sqlite: For SQLite backend (default)'
)
provides=('echidnabot')
conflicts=('echidnabot-git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/hyperpolymath/echidnabot/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('SKIP')

build() {
    cd "$pkgname-$pkgver"
    cargo build --release
}

check() {
    cd "$pkgname-$pkgver"
    cargo test --release
}

package() {
    cd "$pkgname-$pkgver"

    # Install binary
    install -Dm755 "target/release/echidnabot" "$pkgdir/usr/bin/echidnabot"

    # Install license
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

    # Install documentation
    install -Dm644 README.adoc "$pkgdir/usr/share/doc/$pkgname/README.adoc"

    # Install systemd service (optional)
    install -Dm644 /dev/stdin "$pkgdir/usr/lib/systemd/system/echidnabot.service" <<EOF
[Unit]
Description=ECHIDNA Proof Verification CI Bot
After=network.target

[Service]
Type=simple
User=echidnabot
ExecStart=/usr/bin/echidnabot serve
Restart=on-failure
Environment=ECHIDNABOT_CONFIG=/etc/echidnabot/config.toml

[Install]
WantedBy=multi-user.target
EOF
}
