# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=oras-cli
pkgver=1.2.0
pkgrel=0
pkgdesc="OCI registry client"
url="https://oras.land/cli"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/oras-project/oras/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/oras-$pkgver"

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

build() {
	local _goldflags="
	-X oras.land/oras/internal/version.Version=$pkgver
	-X oras.land/oras/internal/version.BuildMetadata=
	-X oras.land/oras/internal/version.GitCommit=AlpineLinux
	-X oras.land/oras/internal/version.GitTreeState=clean
	"
	go build -v -ldflags "$_goldflags" ./cmd/oras

	for shell in bash fish zsh; do
		./oras completion $shell > oras.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 oras -t "$pkgdir"/usr/bin/

	install -Dm644 oras.bash \
		"$pkgdir"/usr/share/bash-completion/completions/oras
	install -Dm644 oras.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/oras.fish
	install -Dm644 oras.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_oras
}

sha512sums="
c90c9619f392e923a5515895dd93ce24d3fec7279109e7ce10ae14b7c86dd8ccc530fe99164d0e1a82d1be1fea1ee3e91f7211f7b9e4dae41fb9d1619c87093d  oras-cli-1.2.0.tar.gz
"
