oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env bash
2set -euo pipefail
3export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}amadan.net/oficina/estilo.git"
4
5test "$#" -ge 1
6test "$#" -le 2
7# The output path has to be absolute before the cd into the archive
8# below, and it has to resolve even though the file does not exist yet.
9# `realpath -m` does that on Linux, where this has always run, but BSD
10# realpath has no -m, so it fails on a Mac. dirname + pwd is the same
11# thing in POSIX, once the directory is there to cd into.
12docs_output_dir=$(dirname -- "$1")
13mkdir -p -- "$docs_output_dir"
14docs_output=$(cd -- "$docs_output_dir" && pwd)/$(basename -- "$1")
15cd "$(dirname "$0")/.."
16docs_revision=$(git rev-parse --verify "${2:-HEAD}^{commit}")
17# What the built binary answers GET /api/version with. rastrillo's
18# BuildVersion defaults to "dev", and the platform's deploy check
19# compares that field against the release it believes it adopted — so an
20# unstamped binary makes the check incapable of failing.
21#
22# git describe --tags --always resolves to the tag when the revision
23# carries one and to the same abbreviated sha when it does not, so a
24# published release reports the name it was published under and an
25# ordinary build still says something true about itself. Name it
26# yourself for a one-off: DOCS_VERSION=v0.1.0-wip scripts/build-release.sh out
27docs_version="${DOCS_VERSION:-$(git describe --tags --always "$docs_revision")}"
28docs_source=$(mktemp -d)
29trap 'rm -rf -- "$docs_source"' EXIT
30git archive "$docs_revision" | tar -x -C "$docs_source"
31cd "$docs_source"
32# -buildvcs=false: this tree is a git archive with no repository of its
33# own, and the version is stamped above. Left on, Go walks up from the
34# temp directory into whatever repository encloses it — on a CI runner,
35# an unrelated checkout it cannot read — and fails the build (2026-09-29).
36CGO_ENABLED=0 GOOS="${GOOS:-linux}" GOARCH="${GOARCH:-arm64}" \
37 go build -mod=readonly -trimpath -buildvcs=false \
38 -ldflags "-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$docs_version" \
39 -o "$docs_output" ./cmd/docs
40
41echo "built $docs_output reporting version $docs_version"
42