#!/bin/bash # Write the short hash of the commit this build came from to BUILD_STAMP. # # bash 3.2-clean and ASCII-only on purpose: the system bash on this Mac is 3.2. # # Why a stamp and not the manifest version: Cowork caches an uploaded plugin, # and plugin.json's version does not change between milestones, so a stale # build would echo the right number and every answer after it would be about # some other build (risk H11). The short hash moves on every commit, which is # exactly the property the check needs. # # The stamp is a build artefact and is gitignored. It is regenerated by # scripts/package_plugin.sh before every archive; a committed stamp would be # false the instant the next commit moved HEAD. # # Usage: # bash scripts/build_stamp.sh # write /BUILD_STAMP # bash scripts/build_stamp.sh --ut # write somewhere else set -eu SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd) OUT="${REPO_ROOT}/BUILD_STAMP" while [ $# -gt 0 ]; do case "$1" in --ut) if [ $# -lt 2 ]; then echo "build_stamp: --ut needs a path" >&2 exit 2 fi OUT="$2" shift 2 ;; -h|--help) sed -n '2,20p' "$0" exit 0 ;; *) echo "build_stamp: unknown argument: $1" >&2 exit 2 ;; esac done if ! git -C "$REPO_ROOT" rev-parse --git-dir >/dev/null 2>&1; then echo "build_stamp: $REPO_ROOT is not a git working tree." >&2 echo "build_stamp: the stamp is the commit this build came from; there is nothing to stamp." >&2 exit 1 fi STAMP=$(git -C "$REPO_ROOT" rev-parse --short HEAD) printf '%s\n' "$STAMP" > "$OUT" echo "build_stamp: $STAMP -> $OUT"