# Maintainer: Davide Ghilardi <davide@ghilardi.io>
pkgname=davit
pkgver=r23.c11bbbc
pkgrel=1
pkgdesc="A safe Kubernetes deployment wrapper & TUI built with Rust"
arch=('x86_64')
url="https://github.com/dghilardi/davit"
license=('MIT')
depends=('gcc-libs' 'glibc')
makedepends=('cargo' 'git')
source=("${pkgname}::git+file://${startdir}/../../")
sha256sums=('SKIP')
options=('!lto')

pkgver() {
  cd "$srcdir/$pkgname"
  if git describe --long --tags >/dev/null 2>&1; then
    git describe --long --tags | sed 's/^v//;s/\([^-]*\)-\([^-]*\)-g\([^-]*\)/\1.r\2.\3/'
  else
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
  fi
}

build() {
  cd "$srcdir/$pkgname"
  export CARGO_TARGET_DIR="$startdir/../../target"
  cargo build --frozen --release --all-features
}

check() {
  cd "$srcdir/$pkgname"
  export CARGO_TARGET_DIR="$startdir/../../target"
  cargo test --frozen
}

package() {
  cd "$srcdir/$pkgname"
  install -Dm755 "$startdir/../../target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
  if [ -f "LICENSE" ]; then
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  fi
}
