# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=alertmanager
pkgver=0.27.0
pkgrel=5
pkgdesc="Prometheus Alertmanager"
url="https://github.com/prometheus/alertmanager"
arch="all"
license="Apache-2.0"
install="$pkgname.pre-install"
makedepends="go"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/prometheus/alertmanager/archive/v$pkgver.tar.gz
	alertmanager.confd
	alertmanager.initd
"
subpackages="$pkgname-openrc"
options="!check" # timing-sensitive upstream tests

# secfixes:
#   0.26.0-r0:
#     - CVE-2023-40577

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

build() {
	go mod vendor
	for cmd in amtool alertmanager
	do
		go build \
			-trimpath \
			-mod=vendor \
			-ldflags "-extldflags \"$LDFLAGS\" \
				-X github.com/prometheus/common/version.Version=$pkgver \
				-X github.com/prometheus/common/version.Revision=$pkgrel \
				-X github.com/prometheus/common/version.Branch=Alpine \
				-X github.com/prometheus/common/version.BuildUser=Alpine \
				-X github.com/prometheus/common/version.BuildDate=2020-01-08" \
			./cmd/$cmd
	done
}

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

package() {
	install -Dm755 alertmanager "$pkgdir"/usr/bin/alertmanager
	install -Dm755 amtool "$pkgdir"/usr/bin/amtool

	install -Dm755 "$srcdir"/alertmanager.initd \
		"$pkgdir"/etc/init.d/alertmanager
	install -Dm644 "$srcdir"/alertmanager.confd \
		"$pkgdir"/etc/conf.d/alertmanager
	install -dm644 "$pkgdir"/var/lib/alertmanager/data

	install -Dm644 examples/ha/alertmanager.yml \
		"$pkgdir"/etc/alertmanager/alertmanager.yml
}

sha512sums="
9f6cee6d19ebdcfb655be329899759c19af0bb0a7123a63eb4e43b590d2e443ff7416a6d17f581cc1b9cbf56f9e6a536790cd191b80add2be90569d5e8a72004  alertmanager-0.27.0.tar.gz
58420cf10ed51ec389d21ffdd5b4a0e588f0dc78b1069e32d0db1e0215f64c1c980d8f539ae902839f2f9342090b50ce1db756839f3676ee18b77548ce8f99c8  alertmanager.confd
783636612f4521a042e890b3c53fa8c859574a533f540f01bbbb2b12d28b7998c69592e4c5f4d8868d32401ed93ae92ab1fa03129cc9a741d1221cd76eb4fb6b  alertmanager.initd
"
