# 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 READ FROM THE ENVIRONMENT and must stay that way. CI used to `sed`
# the literal below in place before calling abuild; that rewrites a tracked file
# inside the checkout, and Go decides half of the VCS stamp it puts into every
# binary — vcs.modified — from exactly that. Measured on go1.26.5: one `sed` of
# APKBUILD makes every binary abuild compiles afterwards record itself as
# "<sha>-dirty" for the life of the apk. The export cannot do that. .gitignore
# covers the rest of what abuild writes into this directory.
#
# .build.yml's version task exports PKGVER out of a single `git describe`: a tag
# (v0.2.0 -> 0.2.0), a tag plus commits since it (0.2.0_git7, which sorts AFTER
# the release in Alpine's grammar), or 0.0.<commit count> when there is no tag —
# which is where this repository stands today. A local `abuild` has no PKGVER
# and builds 0.0.0, which is what a package built by hand honestly is.
pkgname=dolt.sr.ht
pkgver="${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"
# The hook subpackage carries dolt-git-hook alone: it is installed into the
# git.sr.ht container (as its post-update-script), not the dolt one, and
# pulling the full service package in there would drag doltsrht along.
subpackages="$pkgname-hook:hook"
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"
# abuild redirects GOCACHE into $tmpdir (wiped after packaging), and an
# upstream typo makes GOMODCACHE follow GOCACHE's value rather than its
# own. Re-pin both to the stable home locations here — after abuild's own
# exports — so CI's cache_restore/cache_save tasks see them survive.
export GOCACHE="$HOME/.cache/go-build"
export GOMODCACHE="$HOME/go/pkg/mod"
# `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.
#
# -trimpath so the binaries do not carry this builder's directory layout,
# and -modcacherw for a reason beyond tidiness: without it the module cache
# is left read-only, and the CI cache tarball made from it cannot be
# unpacked on the next build (mkdir into 0555 dirs fails).
CGO_ENABLED=0 make all-bin GO_TAGS="$GO_TAGS" GOFLAGS="-trimpath -modcacherw"
# 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 instead. `make check-css` and not the `ls` that
# stood here: two hashed stylesheets are as wrong as none and quieter, since
# web/router.go resolves the glob and takes the first match.
make check-css
}
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.
#
# `install-files` and not `install`, and no CGO_ENABLED or GOFLAGS beside it,
# because this function must not compile anything. abuild runs package() in a
# FRESH abuild process under fakeroot (abuild.in's rootpkg), which re-sources
# this file and never calls build(): the cache pins above are gone here and
# cannot be restored — abuild's own GOMODCACHE line overwrites them — so a
# `make install` staged a second compilation of all three binaries, made from
# a cold module cache and with none of the flags above, and it was that copy
# that went into the apk while build()'s checks were left behind with the
# copy nobody shipped.
make install-files PREFIX="$pkgdir/usr"
}
hook() {
pkgdesc="post-update hook that provisions companion Dolt databases (for the git.sr.ht container)"
amove usr/bin/dolt-git-hook
}