Files
computer-playbook/scripts/github/update/open/role_prs.sh
T
kevinveenbirkenbachandClaude Fable 5 40e553069d refactor(structure): nest prefix-grouped sibling files into subfolders
Move files that share a delimiter-bounded name prefix within a folder (threshold 2) into a subfolder named after the prefix, dropping the prefix from the filename. Covers plugins/filter (docker, generate, has, merge, get/all), env handler subpackages, utils/roles/entity, utils/tests/swarm/write, role SQL/scripts/templates, keycloak/mailu task-includes, shared tasks/utils/load, and CI scripts. Update every import, query_file/script/include_tasks/src/lookup target, compose bind mount, and python -m path to the new locations.

Extend the prefix-grouped-files lint to threshold 2 with dir-level .nocheck and file-head nocheck opt-outs, and skip groups whose shortest member's stem equals the shared prefix. Keep flat only where a loader forbids nesting: WordPress mu-plugins and the docs/requirements namespace. Ansible filter discovery is recursive, so nested filters stay Jinja-resolvable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 20:00:03 +02:00

59 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Opens one update PR per top-level entry that changed under the given root
# (e.g. one PR per role under roles/), instead of a single combined PR.
# The actual dedup/push/PR logic is reused from pr.sh; this wrapper only
# isolates one entry's changes per call.
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ROOT="${1:?Usage: open_role_prs.sh <root-dir> (e.g. roles)}"
: "${GH_TOKEN:?Missing GH_TOKEN}"
: "${UPDATE_BRANCH_PREFIX:?Missing UPDATE_BRANCH_PREFIX}"
: "${UPDATE_COMMIT_MESSAGE:?Missing UPDATE_COMMIT_MESSAGE}"
: "${UPDATE_PR_TITLE:?Missing UPDATE_PR_TITLE}"
: "${UPDATE_PR_BODY:?Missing UPDATE_PR_BODY}"
date_suffix="$(date +%Y%m%d)"
git config user.name >/dev/null 2>&1 || git config user.name "github-actions[bot]"
git config user.email >/dev/null 2>&1 || git config user.email "github-actions[bot]@users.noreply.github.com"
base="$(git rev-parse HEAD)"
git add -A -- "${ROOT}"
if git diff --cached --quiet; then
echo "No ${ROOT} changes to split into per-entry PRs."
exit 0
fi
git commit --quiet -m "scratch: ${ROOT} updates"
scratch="$(git rev-parse HEAD)"
git reset --quiet --hard "${base}"
mapfile -t entries < <(
git diff --name-only "${base}" "${scratch}" -- "${ROOT}/" |
sed -E "s#^${ROOT}/([^/]+)/.*#\1#;t;d" |
sort -u
)
echo "Changed ${ROOT} entries: ${entries[*]:-(none)}"
for entry in "${entries[@]}"; do
[[ -z "${entry}" ]] && continue
echo "=== Opening PR for ${ROOT}/${entry} ==="
git checkout --quiet --force --detach "${base}"
git checkout --quiet "${scratch}" -- "${ROOT}/${entry}/"
UPDATE_BRANCH_SUFFIX="${entry}-${date_suffix}" \
UPDATE_DEDUPE_PREFIX="${UPDATE_BRANCH_PREFIX}-${entry}-" \
UPDATE_COMMIT_MESSAGE="${UPDATE_COMMIT_MESSAGE} (${entry})" \
UPDATE_PR_TITLE="${UPDATE_PR_TITLE} (${entry})" \
UPDATE_PR_BODY="${UPDATE_PR_BODY}"$'\n\n'"Scope: \`${ROOT}/${entry}\`." \
bash "${SCRIPT_DIR}/pr.sh" "${ROOT}/${entry}"
done
git checkout --quiet --force --detach "${base}" || true