fix: make the public export fail closed and add e-mail, host and tooling checks
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,22 +1,92 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Build a clean, single-commit tree of the current HEAD for a fresh public repository. Nothing is pushed.
|
# Build a clean, single-commit tree of the current HEAD for a fresh public repository. Nothing is pushed.
|
||||||
# Usage: [TESSERA_PRIVATE_TERMS=/path/to/terms.txt] scripts/export-public.sh /path/to/empty-dir
|
#
|
||||||
|
# Usage: TESSERA_PRIVATE_TERMS=/path/to/terms.txt scripts/export-public.sh /path/to/empty-dir
|
||||||
|
# scripts/export-public.sh --allow-unchecked /path/to/empty-dir
|
||||||
#
|
#
|
||||||
# TESSERA_PRIVATE_TERMS names a file, kept outside the repository, with one term per line (host names,
|
# TESSERA_PRIVATE_TERMS names a file, kept outside the repository, with one term per line (host names,
|
||||||
# customer names, internal systems). If any of them occurs in the exported tree the export is refused.
|
# customer names, internal systems, personal names). The export is refused when any term occurs in the exported
|
||||||
|
# tree. The variable must be set and the file must exist and contain at least one term; otherwise the script fails.
|
||||||
|
# Pass --allow-unchecked only if you knowingly want to skip that check.
|
||||||
|
#
|
||||||
|
# Independently of the terms file, a given terms file also enables two pattern checks on the export: personal
|
||||||
|
# e-mail addresses (anything that is not a documentation/placeholder address) and "@senkensha"-style hosts.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
out="${1:?target directory}"
|
|
||||||
|
allow_unchecked=0
|
||||||
|
out=""
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--allow-unchecked) allow_unchecked=1 ;;
|
||||||
|
-*) echo "unknown option: $arg" >&2; exit 2 ;;
|
||||||
|
*) [ -z "$out" ] || { echo "only one target directory" >&2; exit 2; }; out="$arg" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[ -n "$out" ] || { echo "usage: $0 [--allow-unchecked] <empty-target-dir>" >&2; exit 2; }
|
||||||
|
|
||||||
|
terms="${TESSERA_PRIVATE_TERMS:-}"
|
||||||
|
if [ "$allow_unchecked" -eq 0 ]; then
|
||||||
|
if [ -z "$terms" ]; then
|
||||||
|
echo "refusing to export: TESSERA_PRIVATE_TERMS is not set (or pass --allow-unchecked to skip the private-terms check)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ ! -f "$terms" ]; then
|
||||||
|
echo "refusing to export: TESSERA_PRIVATE_TERMS=$terms is not a file" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! grep -q '[^[:space:]]' "$terms"; then
|
||||||
|
echo "refusing to export: $terms contains no terms" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$out"
|
||||||
[ -z "$(ls -A "$out" 2>/dev/null)" ] || { echo "target must be empty" >&2; exit 1; }
|
[ -z "$(ls -A "$out" 2>/dev/null)" ] || { echo "target must be empty" >&2; exit 1; }
|
||||||
root="$(git rev-parse --show-toplevel)"
|
root="$(git rev-parse --show-toplevel)"
|
||||||
git -C "$root" diff --quiet HEAD || { echo "commit or stash first" >&2; exit 1; }
|
git -C "$root" diff --quiet HEAD || { echo "commit or stash first" >&2; exit 1; }
|
||||||
git -C "$root" archive HEAD | tar -x -C "$out"
|
git -C "$root" archive HEAD | tar -x -C "$out"
|
||||||
if [ -n "${TESSERA_PRIVATE_TERMS:-}" ]; then
|
|
||||||
if grep -rIl -i -F -f "$TESSERA_PRIVATE_TERMS" "$out" --exclude-dir=node_modules >/dev/null; then
|
# Local tooling and agent state never belongs in a public tree, even if an old commit tracked it.
|
||||||
|
for path in .serena .claude .cursor .idea .vscode graft floorplan .ignore web/AGENTS.md AGENTS.md CLAUDE.md \
|
||||||
|
web/blackhole-proto.html tasks; do
|
||||||
|
rm -rf "${out:?}/$path"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$terms" ] && [ -f "$terms" ] && grep -q '[^[:space:]]' "$terms"; then
|
||||||
|
fail=0
|
||||||
|
# 1. literal private terms (case-insensitive)
|
||||||
|
if hits="$(grep -rIl -i -F -f "$terms" "$out" --exclude-dir=node_modules)"; [ -n "$hits" ]; then
|
||||||
echo "private terms found in:" >&2
|
echo "private terms found in:" >&2
|
||||||
grep -rIl -i -F -f "$TESSERA_PRIVATE_TERMS" "$out" --exclude-dir=node_modules >&2
|
echo "$hits" >&2
|
||||||
exit 1
|
fail=1
|
||||||
fi
|
fi
|
||||||
|
# 2. personal e-mail addresses: any address that is not a documentation or no-reply placeholder
|
||||||
|
email='[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+'
|
||||||
|
placeholder='@(example\.(com|org|net|invalid)|[A-Za-z0-9.-]*\.(example|invalid|test|localhost)|users\.noreply\.github\.com|noreply\.[A-Za-z0-9.-]+)$|:(noreply|no-reply)@'
|
||||||
|
if hits="$(grep -rIoE "$email" "$out" --exclude-dir=node_modules --exclude=Cargo.lock --exclude=package-lock.json \
|
||||||
|
| grep -vE "$placeholder" || true)"; [ -n "$hits" ]; then
|
||||||
|
echo "possible personal e-mail addresses (review, then remove or allow-list):" >&2
|
||||||
|
echo "$hits" | sort -u >&2
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
# 3. "@senkensha"-style hosts (any host label containing the org name after an @ or in a URL)
|
||||||
|
if hits="$(grep -rIiEl '@[A-Za-z0-9.-]*senkensha|https?://[A-Za-z0-9.-]*senkensha' "$out" --exclude-dir=node_modules || true)"; [ -n "$hits" ]; then
|
||||||
|
echo "organisation-specific hosts found in:" >&2
|
||||||
|
echo "$hits" >&2
|
||||||
|
fail=1
|
||||||
|
fi
|
||||||
|
[ "$fail" -eq 0 ] || exit 1
|
||||||
else
|
else
|
||||||
echo "note: TESSERA_PRIVATE_TERMS is not set, so no check for private terms was made" >&2
|
echo "warning: --allow-unchecked given, so no check for private terms or personal e-mail addresses was made" >&2
|
||||||
fi
|
fi
|
||||||
echo "clean tree at $out; review it, then: git init && git add -A && git commit"
|
|
||||||
|
cat <<EOF
|
||||||
|
clean tree at $out; review it, then create the public history with a neutral author, for example:
|
||||||
|
|
||||||
|
cd "$out"
|
||||||
|
git init
|
||||||
|
git add -A
|
||||||
|
git -c user.name="<PUBLIC NAME>" -c user.email="<PUBLIC EMAIL OR noreply ADDRESS>" commit -m "Initial release"
|
||||||
|
|
||||||
|
Do not run a bare 'git commit' there: it would use your global git identity.
|
||||||
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user