Replace script/update-policy with a short wget-and-commit script (closes #165) #181

Merged
clawbot merged 5 commits from issue-165-simple-update-policy into next 2026-11-18 23:23:50 +01:00
Showing only changes of commit 6378311ac5 - Show all commits
+25 -21
View File
@@ -19,41 +19,45 @@ die() {
exit 1 exit 1
} }
cd "$ROOT" main() {
[ ! -e prompts/REPO_POLICIES.md ] || cd "$ROOT"
[ ! -e prompts/REPO_POLICIES.md ] ||
die "this is the prompts repo, where these files come from" die "this is the prompts repo, where these files come from"
[ ! -e REPO_POLICIES.md ] || [ ! -e REPO_POLICIES.md ] ||
die "REPO_POLICIES.md is at the root;" \ die "REPO_POLICIES.md is at the root;" \
"move it into docs/ with git mv and fix the links to it first" "move it into docs/ with git mv and fix the links to it first"
paths="" paths=""
for entry in $FILES; do for entry in $FILES; do
paths="$paths ${entry#*:}" paths="$paths ${entry#*:}"
done done
[ -z "$(git status --porcelain -- $paths)" ] || [ -z "$(git status --porcelain -- $paths)" ] ||
die "commit or discard your changes to these files first:$paths" die "commit or discard your changes to these files first:$paths"
# Every file is fetched before any is replaced. The temporary directory # Every file is fetched before any is replaced. The temporary
# is inside the repo so that mv renames: the running script is replaced # directory is inside the repo so that mv renames: the running script
# by a new file, never rewritten in place. # is replaced by a new file, never rewritten in place.
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")" tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
trap 'rm -rf "$tmp"' EXIT trap 'rm -rf "$tmp"' EXIT
for entry in $FILES; do for entry in $FILES; do
mkdir -p "$tmp/$(dirname "${entry#*:}")" mkdir -p "$tmp/$(dirname "${entry#*:}")"
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" || wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
die "cannot fetch $RAW_URL/${entry%%:*}" die "cannot fetch $RAW_URL/${entry%%:*}"
done done
chmod 755 "$tmp/script/update-policy" chmod 755 "$tmp/script/update-policy"
for path in $paths; do for path in $paths; do
mkdir -p "$(dirname "$path")" mkdir -p "$(dirname "$path")"
mv "$tmp/$path" "$path" mv "$tmp/$path" "$path"
done done
git add -- $paths git add -- $paths
if git diff --cached --quiet -- $paths; then if git diff --cached --quiet -- $paths; then
echo "update-policy: already current, nothing to commit" echo "update-policy: already current, nothing to commit"
else else
git commit -q -m "Update policy files from prompts" -- $paths git commit -q -m "Update policy files from prompts" -- $paths
echo "update-policy: committed; review it, then push" echo "update-policy: committed; review it, then push"
fi fi
}
main "$@"