#!/bin/sh
# Writes the commit of the checkout into src/cmd/rille/build_commit.mbt, so
# that `rille --version` and every output of a published build name it.
# Run before building a release (the publish workflow's prepare step
# does). Refuses a working tree with changes: the stamped commit would not
# be the source that is built. Do not commit the stamped file.
set -eu
cd "$(dirname "$0")/.."
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
  echo "stamp-build-commit: the working tree has changes; commit them first" >&2
  exit 1
fi
commit="$(git rev-parse HEAD)"
cat > src/cmd/rille/build_commit.mbt <<MBT
// The commit this build of rille was made from, written by
// scripts/stamp-build-commit.sh. Do not commit this stamped file.

///|
let build_commit : String? = Some("$commit")
MBT
echo "stamp-build-commit: $commit"
