| 1 | #!/bin/sh |
| 2 | # make release: build every release artifact from one fixed commit, in a |
| 3 | # tree of its own, and record provenance only if that is what was built. |
| 4 | # |
| 5 | # scripts/release-isolated.sh <goos> <goarch> |
| 6 | # |
| 7 | # The checkout you run this from is only asked which commit HEAD is. The |
| 8 | # build happens in a fresh clone checked out at exactly that commit, under |
| 9 | # $TMPDIR, so an edit made here while it runs cannot reach a binary. (A |
| 10 | # clone, not a git worktree: go stamps a binary with its commit only where |
| 11 | # .git is a directory.) The |
| 12 | # build tree must be clean and at that commit before the build and again |
| 13 | # after it, and every binary must say so itself (go version -m: |
| 14 | # vcs.revision is the commit, vcs.modified is false) before |
| 15 | # scripts/staged-artifacts.py writes the provenance manifest. Anything |
| 16 | # else refuses, and nothing is copied into releases/. |
| 17 | set -eu |
| 18 | goos=$1 |
| 19 | goarch=$2 |
| 20 | refuse() { |
| 21 | echo "refusing to release: $1" >&2 |
| 22 | exit 1 |
| 23 | } |
| 24 | commit=$(git rev-parse HEAD) |
| 25 | version=$(git rev-parse --short HEAD) |
| 26 | [ -z "$(git status --porcelain)" ] || refuse "refusing to build a release from a dirty tree" |
| 27 | base=${TMPDIR:-${XDG_CACHE_HOME:-$HOME/.cache}/equipo} |
| 28 | mkdir -p "$base" |
| 29 | scratch=$(mktemp -d "$base/equipo-release.XXXXXX") |
| 30 | tree=$scratch/src |
| 31 | trap 'rm -rf "$scratch"' EXIT |
| 32 | trap 'exit 1' HUP INT TERM |
| 33 | git clone --quiet --no-hardlinks . "$tree" |
| 34 | (cd "$tree" && git checkout --quiet --detach "$commit") |
| 35 | # The build tree: at the commit, nothing changed, nothing untracked. |
| 36 | # Build output (releases/, the instance's bundle) is ignored by git. |
| 37 | pristine() { |
| 38 | (cd "$tree" && [ "$(git rev-parse HEAD)" = "$commit" ] && [ -z "$(git status --porcelain)" ]) |
| 39 | } |
| 40 | pristine || refuse "the build tree is not a clean checkout of $commit" |
| 41 | make -C "$tree" --no-print-directory release-in-tree RELEASE_GOOS="$goos" RELEASE_GOARCH="$goarch" |
| 42 | pristine || refuse "the build tree changed during the build" |
| 43 | # This checkout may have moved on meanwhile; a release of the commit it |
| 44 | # named is still wanted only if it still names it, unchanged. |
| 45 | [ "$(git rev-parse HEAD)" = "$commit" ] && git diff --quiet HEAD || refuse "this checkout changed during the build" |
| 46 | (cd "$tree" && python3 scripts/staged-artifacts.py manifest "$version" --instance "releases/equipo-$goos-$goarch-$version") |
| 47 | mkdir -p releases |
| 48 | cp -R "$tree/releases/." releases/ |
| 49 | echo "built releases/equipo-$goos-$goarch-$version from $commit" |
| 50 | echo "stage it first (scripts/staging-thin.py build/deploy/runner/suite), then deploy only" |
| 51 | echo "the exact bytes staging passed, through the drained cutover:" |
| 52 | echo " make staged-check && scripts/cutover-thin.sh $version" |
| 53 | |