#!/usr/bin/env bash # Every commit path the tooling owns runs git with TZ=UTC, so no commit carries the local offset (review round 4, # ledger G14; docs/plans/history-rewrite.md step 7). The class check (standing rule, 5 October 2026): any script under # tools/, packaging/, infra/ or .github/ that invokes `git commit` (shell) or `['commit'` (node) must set TZ=UTC in # the same file, or this fails. It also prints how many commits on the current branch still carry a non-UTC offset # (the history rewrite is the owner's date; the count is information, not a failure). # # bash tools/ci/commit-tz-check.sh [--self-test] set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" check_tree() { # -> 0 when clean; prints offenders local root="$1" bad=0 f while IFS= read -r f; do if grep -Eq "git commit|git\\b.*\\['commit'|\\['commit',|\"commit\"," "$f" 2>/dev/null; then if ! grep -Eq "TZ=UTC|TZ: 'UTC'|TZ: \"UTC\"" "$f"; then echo "commit without TZ=UTC: ${f#$root/}"; bad=1; fi fi done < <(find "$root/tools" "$root/packaging" "$root/infra" "$root/.github" -type f \( -name '*.sh' -o -name '*.mjs' -o -name '*.js' -o -name '*.yml' -o -name '*.yaml' -o -name '*.py' \) 2>/dev/null | grep -v '/node_modules/' | grep -v '/fixtures/') return $bad } if [ "${1:-}" = "--self-test" ]; then T="$(mktemp -d)"; trap 'rm -rf "$T"' EXIT mkdir -p "$T/tools" "$T/packaging" "$T/infra" "$T/.github" printf '#!/bin/sh\nexport TZ=UTC\ngit commit -m x\n' > "$T/tools/good.sh" printf "const git = a => run('git', a, { env: { TZ: 'UTC' } }); git(['commit', '-m', 'x']);\n" > "$T/tools/good.mjs" check_tree "$T" >/dev/null || { echo "self-test: the clean tree failed"; exit 1; } printf '#!/bin/sh\ngit commit -m x\n' > "$T/packaging/bad.sh" if check_tree "$T" >/dev/null; then echo "self-test: the bad tree passed"; exit 1; fi echo "commit-tz-check self-test: fires on the bad case, passes the good one" exit 0 fi if check_tree "$ROOT"; then echo "commit-tz-check: every tooling commit path sets TZ=UTC"; else exit 1; fi if git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then n="$(git -C "$ROOT" log --format='%ad %cd' --date=raw 2>/dev/null | grep -cvE '^\S+ \+0000 \S+ \+0000$' || true)" echo "commits on this branch with a non-UTC offset (author or committer): $n (0 after the history rewrite, docs/plans/history-rewrite.md)" fi