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