# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=oras-cli
pkgver=1.2.2
pkgrel=5
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="
4090bde156afa77e40b303b5b9384edf41f2f05a224b99705433f4245110cfc33db6d7458242e3e0f3e5cc6f242868a09eac1d803377703726f9dc467fe8a34f  oras-cli-1.2.2.tar.gz
"
