# 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, not rewritten in place. CI's `version`
# task exports PKGVER from one `git describe`: a tag becomes `0.2.0`, a tag plus
# commits becomes `0.2.0_git7` (which sorts AFTER the release in Alpine's
# comparison), and a repository with no tags at all falls back to
# `0.0.<commit count>`. The literal below is what a local `abuild` that was
# handed no PKGVER honestly builds.
#
# The earlier arrangement had CI `sed` that literal here before abuild ran, and
# it cannot stand: Go records vcs.modified in every binary compiled inside a
# repository and reads that flag from `git status --porcelain`, so a CI task
# that rewrites a tracked file in the checkout stamps every packaged binary
# dirty for the life of the apk. Measured on go1.26.5.
pkgname=spec.sr.ht
pkgver="${PKGVER:-0.0.0}"
pkgrel=0
pkgdesc="Reviewable document storage for humans and agents"
url="https://sourcecraft.dev/bigbes/sr-ht-spec"
arch="x86_64"
license="MIT"
# !check — tests want a live Postgres and a git work area
# !tracedeps — CGO_ENABLED=0, so the binaries are static
options="!check !tracedeps"
source=""
builddir="$startdir"
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"
# CSS strictly before the binaries: web/ go:embed-s static/, so a
# stylesheet built afterwards would never make it into the binary. The
# shared scss partials are assembled by CI at ASSETS/scss (no apk ships
# them).
make css ASSETS=/usr/share/sourcehut
# The stylesheet has to exist before the compiler runs and nothing else
# says so: `go build` succeeds perfectly well with an unstyled static/,
# because //go:embed takes the directory and not the file, and the first
# sign of trouble would be an unstyled page in production. `make install`
# runs this too; here it fails the build before anything is staged.
make check-css
# -modcacherw matters beyond convenience: without it the module cache is
# extracted read-only, and the CI cache tarball made from it can't be
# unpacked on the next build (mkdir into 0555 dirs fails).
CGO_ENABLED=0 make build GOFLAGS="-trimpath -modcacherw"
}
package() {
cd "$builddir"
# This Makefile honours DESTDIR; ASSETS must stay the real runtime path so
# migrations and schema land where specsrht-migrate resolves them. Static
# assets are not installed at all — they are inside the binary, embedded by
# web/templates.go.
#
# `install-files` and not `install`, because this function must not compile.
# abuild runs package() in a FRESH abuild process under fakeroot, which
# re-sources this file and never calls build(): nothing build() exported
# reaches here, the Go cache pins above included, so `make install` — whose
# .PHONY binary targets always rerun — relinked both binaries from a cold
# cache and shipped a SECOND binary that nothing in this pipeline had
# tested. `install -Dm755 specsrht` on a missing file is a fatal error
# naming it, so a package() reached without a build() says so.
make install-files DESTDIR="$pkgdir" PREFIX=/usr \
ASSETS=/usr/share/sourcehut
}