# Maintainer: bigbes <bigbes@gmail.com>
#
# Built by builds.sr.ht (.build.yml) and published to our own apk repo at
# repo.bigb.es/alpine/v3.22/bigbes. The srht deployment installs it from there
# instead of cloning and compiling this repo inside its Dockerfile.
#
# pkgver is rewritten by CI to 0.0.<commit count> before abuild runs — a
# monotonic, unique-per-commit version that the deployment can pin.
pkgname=dolt.sr.ht
pkgver=0.0.0
pkgrel=0
pkgdesc="Dolt database hosting for a sourcehut instance"
url="https://sourcecraft.dev/bigbes/sr-ht-dolt"
arch="x86_64"
license="MIT"
# !check      — tests want a live Postgres and a chunk store
# !tracedeps  — CGO_ENABLED=0 with -tags gms_pure_go, so the binaries are
#               static: no ICU, no gozstd, nothing to trace
options="!check !tracedeps"

source=""
builddir="$startdir"

# The pure-Go build tag is what keeps this package free of cgo: it selects
# go-mysql-server's stdlib regexp instead of go-icu-regex (the SQL engine is
# never run here), and a replace directive backs gozstd with a klauspost shim.
# Dropping it would pull in libicu and make the package arch/libc-specific.
export GO_TAGS="gms_pure_go"

build() {
	cd "$builddir"
	# `make all` is all-bin ONLY — this Makefile deliberately keeps the CSS off
	# the default path because sassc/minify aren't always on a dev machine. So
	# `css` has to be asked for by name; building `all` alone silently produces
	# a package with no stylesheet.
	CGO_ENABLED=0 make all-bin GO_TAGS="$GO_TAGS"
	# Needs the shared sourcehut scss partials pre-assembled at ASSETS/scss (no
	# apk ships them); CI does that before calling abuild.
	make css ASSETS=/usr/share/sourcehut

	# install-share copies static/*.css under `2>/dev/null || true`, so a
	# stylesheet that never got built would ship as an unstyled service without
	# failing anything. Assert it exists instead. The hashed copy is the one the
	# service finds by globbing its static dir at startup.
	ls static/main.min.*.css >/dev/null
}

package() {
	cd "$builddir"
	# This Makefile's install rules do not honour DESTDIR (they write to
	# $(BINDIR)/$(SHAREDIR) directly), so the staging dir is passed as PREFIX.
	# MIGRATIONDIR and STATICDIR are both derived from SHAREDIR, so they follow.
	make install PREFIX="$pkgdir/usr"
}
