iftypeset/scripts/checkpoint.sh
2026-01-03 20:29:35 +00:00

65 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
ts="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
safe_ts="$(date -u +"%Y-%m-%dT%H-%M-%SZ")"
note="${1:-}"
mkdir -p out/checkpoints
echo "== running ci ==" >&2
ci_json="$(./scripts/ci.sh)"
echo "$ci_json" > "out/checkpoints/ci_${safe_ts}.json"
tar_path="out/checkpoints/iftypeset_checkpoint_${safe_ts}.tar.gz"
echo "== creating snapshot ${tar_path} ==" >&2
tar \
--exclude=".git" \
--exclude=".venv" \
--exclude="out" \
-czf "$tar_path" \
.forgejo .gitignore README.md STATUS.md app docs fixtures forgejo pyproject.toml requirements.txt scripts spec src tests tools
sha="$(sha256sum "$tar_path" | awk '{print $1}')"
cat > "out/checkpoints/checkpoint_${safe_ts}.md" <<EOF
# iftypeset checkpoint
- timestamp_utc: ${ts}
- snapshot: ${tar_path}
- snapshot_sha256: ${sha}
- ci: \`out/checkpoints/ci_${safe_ts}.json\`
$( [ -n "${note}" ] && printf -- "- note: %s\n" "${note}" )
EOF
if [ ! -s docs/CHECKPOINTS.md ]; then
cat > docs/CHECKPOINTS.md <<'EOF'
# Checkpoints
Durable restore points for this repo (useful when chat context resets).
How to create a checkpoint:
- `./scripts/checkpoint.sh "short note about what changed"`
Each entry records the snapshot tarball path + sha256 and the CI JSON for that moment.
EOF
fi
cat >> docs/CHECKPOINTS.md <<EOF
## ${ts}
- snapshot: \`${tar_path}\`
- snapshot_sha256: \`${sha}\`
- ci_json: \`out/checkpoints/ci_${safe_ts}.json\`
$( [ -n "${note}" ] && printf -- "- note: %s\n" "${note}" )
EOF
echo "checkpoint complete: ${tar_path} (sha256=${sha})" >&2