maintainer="Michał Polański <michal@polanski.me>"
pkgname=syft
pkgver=1.19.0
pkgrel=5
pkgdesc="Generate a Software Bill of Materials (SBOM) from container images and filesystems"
url="https://github.com/anchore/syft"
license="Apache-2.0"
arch="all !armhf !armv7 !x86 !ppc64le" # FTBFS on 32-bit arches, ppc64le
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/anchore/syft/archive/v$pkgver/syft-$pkgver.tar.gz"
options="!check" # tests need docker

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

build() {
	go build -ldflags "
		-X main.version=$pkgver
		" \
		-o bin/syft ./cmd/syft

	bin/syft completion bash > $pkgname.bash
	bin/syft completion fish > $pkgname.fish
	bin/syft completion zsh > $pkgname.zsh
}

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

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

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

sha512sums="
2a77f7139ff91473f25f9d71b5dc7fe92f5c46612a6688e748680a9d6be38271a37ad4d1a262b6418233ca8bf600ab0f12a49260b67e7f50002bcad23f42f861  syft-1.19.0.tar.gz
"
