#!/bin/sh # make release: build every release artifact from one fixed commit, in a # tree of its own, and record provenance only if that is what was built. # # scripts/release-isolated.sh # # The checkout you run this from is only asked which commit HEAD is. The # build happens in a fresh clone checked out at exactly that commit, under # $TMPDIR, so an edit made here while it runs cannot reach a binary. (A # clone, not a git worktree: go stamps a binary with its commit only where # .git is a directory.) The # build tree must be clean and at that commit before the build and again # after it, and every binary must say so itself (go version -m: # vcs.revision is the commit, vcs.modified is false) before # scripts/staged-artifacts.py writes the provenance manifest. Anything # else refuses, and nothing is copied into releases/. set -eu goos=$1 goarch=$2 refuse() { echo "refusing to release: $1" >&2 exit 1 } commit=$(git rev-parse HEAD) version=$(git rev-parse --short HEAD) [ -z "$(git status --porcelain)" ] || refuse "refusing to build a release from a dirty tree" base=${TMPDIR:-${XDG_CACHE_HOME:-$HOME/.cache}/equipo} mkdir -p "$base" scratch=$(mktemp -d "$base/equipo-release.XXXXXX") tree=$scratch/src trap 'rm -rf "$scratch"' EXIT trap 'exit 1' HUP INT TERM git clone --quiet --no-hardlinks . "$tree" (cd "$tree" && git checkout --quiet --detach "$commit") # The build tree: at the commit, nothing changed, nothing untracked. # Build output (releases/, the instance's bundle) is ignored by git. pristine() { (cd "$tree" && [ "$(git rev-parse HEAD)" = "$commit" ] && [ -z "$(git status --porcelain)" ]) } pristine || refuse "the build tree is not a clean checkout of $commit" make -C "$tree" --no-print-directory release-in-tree RELEASE_GOOS="$goos" RELEASE_GOARCH="$goarch" pristine || refuse "the build tree changed during the build" # This checkout may have moved on meanwhile; a release of the commit it # named is still wanted only if it still names it, unchanged. [ "$(git rev-parse HEAD)" = "$commit" ] && git diff --quiet HEAD || refuse "this checkout changed during the build" (cd "$tree" && python3 scripts/staged-artifacts.py manifest "$version" --instance "releases/equipo-$goos-$goarch-$version") mkdir -p releases cp -R "$tree/releases/." releases/ echo "built releases/equipo-$goos-$goarch-$version from $commit" echo "stage it first (scripts/staging-thin.py build/deploy/runner/suite), then deploy only" echo "the exact bytes staging passed, through the drained cutover:" echo " make staged-check && scripts/cutover-thin.sh $version"