maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=kubectl-krew
pkgver=0.4.5
pkgrel=2
pkgdesc="Find and install kubectl plugins"
url="https://krew.sigs.k8s.io/"
arch="all !armhf !riscv64 !loongarch64" # kubectl
license="Apache-2.0"
depends="kubectl"
makedepends="go"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/kubernetes-sigs/krew/archive/refs/tags/v$pkgver.tar.gz
	test-use-testing-tmpdir.patch
	"
builddir="$srcdir/krew-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	GOLDFLAGS="
	-X sigs.k8s.io/krew/internal/version.gitCommit=AlpineLinux
	-X sigs.k8s.io/krew/internal/version.gitTag=v$pkgver
	"
	go build -tags netgo -ldflags "$GOLDFLAGS" -o bin/$pkgname ./cmd/krew/main.go
}

check() {
	# uses github api and gets 403
	# shellcheck disable=2046
	KREW_BINARY="$builddir/bin/$pkgname" go test $(go list ./... | grep -Ev '(cmd/internal)')
}

package() {
	install -Dm755 bin/$pkgname "$pkgdir"/usr/bin/$pkgname
}

sha512sums="
afce7b8a68bd535b4c1149db4ebf41b1995e8203b9d8ffb15db5e501492ebb45e8683f400c9d2f54f63b76a9427e17b6d231f35a4c9009f6dfffd5e3082abd16  kubectl-krew-0.4.5.tar.gz
797a0f1361d893289217569e09dd5564fe545eaf2f0b3dc40367c63cb124b8120c5600d190732ced7885a020ae56a9417b49bccb8bca2c87faf72bf3e1359a81  test-use-testing-tmpdir.patch
"
