🐛 fix(thirdparty): prune nested project snapshots
This commit is contained in:
@@ -88,12 +88,38 @@ for entry in data["sources"]:
|
||||
entry.get("upstream_ref", "main"),
|
||||
entry["snapshot_dir"],
|
||||
entry["sync_mode"],
|
||||
"\x1e".join(entry.get("remove_paths", [])),
|
||||
]
|
||||
)
|
||||
)
|
||||
PY
|
||||
}
|
||||
|
||||
read_source_metadata_value() {
|
||||
local key="$1"
|
||||
local source_file="$2"
|
||||
|
||||
if [ ! -f "$source_file" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
sed -n "s/^- ${key}:[[:space:]]*//p" "$source_file" | head -n 1
|
||||
}
|
||||
|
||||
remove_snapshot_paths() {
|
||||
local snapshot_dir="$1"
|
||||
local remove_paths="$2"
|
||||
|
||||
[ -n "$remove_paths" ] || return 0
|
||||
|
||||
local IFS=$'\x1e'
|
||||
read -r -a paths <<< "$remove_paths"
|
||||
for path in "${paths[@]}"; do
|
||||
[ -n "$path" ] || continue
|
||||
rm -rf "$snapshot_dir/$path"
|
||||
done
|
||||
}
|
||||
|
||||
cd "$REPO_DIR"
|
||||
|
||||
git config user.name "$COMMIT_AUTHOR_NAME"
|
||||
@@ -124,8 +150,9 @@ if ! emit_sources_tsv > "$sources_file"; then
|
||||
fi
|
||||
|
||||
changed=0
|
||||
while IFS=$'\x1f' read -r source_id upstream_repo upstream_ref snapshot_dir sync_mode; do
|
||||
while IFS=$'\x1f' read -r source_id upstream_repo upstream_ref snapshot_dir sync_mode remove_paths; do
|
||||
[ -n "$source_id" ] || continue
|
||||
remove_paths_md="${remove_paths//$'\x1e'/,}"
|
||||
|
||||
gh_repo=""
|
||||
if gh_repo="$(github_owner_repo "$upstream_repo" 2>/dev/null)"; then
|
||||
@@ -138,12 +165,10 @@ while IFS=$'\x1f' read -r source_id upstream_repo upstream_ref snapshot_dir sync
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_sha=""
|
||||
if [ -f "$snapshot_dir/SOURCE.md" ]; then
|
||||
current_sha="$(sed -n 's/^- Ref:[[:space:]]*//p' "$snapshot_dir/SOURCE.md" | head -n 1)"
|
||||
fi
|
||||
current_sha="$(read_source_metadata_value "Ref" "$snapshot_dir/SOURCE.md")"
|
||||
current_remove_paths="$(read_source_metadata_value "Remove-Paths" "$snapshot_dir/SOURCE.md")"
|
||||
|
||||
if [ "$latest_sha" = "$current_sha" ]; then
|
||||
if [ "$latest_sha" = "$current_sha" ] && [ "$remove_paths_md" = "$current_remove_paths" ]; then
|
||||
echo "Third-party snapshot is up to date for ${source_id}: $latest_sha"
|
||||
continue
|
||||
fi
|
||||
@@ -169,12 +194,15 @@ while IFS=$'\x1f' read -r source_id upstream_repo upstream_ref snapshot_dir sync
|
||||
git -C "$upstream_dir" archive --format=tar HEAD | tar -xf - -C "$snapshot_dir"
|
||||
fi
|
||||
|
||||
remove_snapshot_paths "$snapshot_dir" "$remove_paths"
|
||||
|
||||
snapshot_date="$(date -u +%Y-%m-%d)"
|
||||
cat > "$snapshot_dir/SOURCE.md" <<EOF
|
||||
# Source
|
||||
|
||||
- Repo: ${upstream_repo%".git"}
|
||||
- Ref: $latest_sha
|
||||
- Remove-Paths: $remove_paths_md
|
||||
- Snapshot: $snapshot_date
|
||||
- Sync-Mode: $sync_mode
|
||||
- Notes: vendored into playbook branch $TARGET_BRANCH
|
||||
|
||||
Reference in New Issue
Block a user