-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improve PR preview site artifact clean-up #6341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,36 +4,30 @@ set -e # Exit on error | |
|
|
||
| echo "Starting gh-pages branch cleanup..." | ||
|
|
||
| REMOVE_PATHS_FILE="/tmp/remove-paths.txt" | ||
| > "$REMOVE_PATHS_FILE" | ||
|
|
||
| dirs_with_visible_files=$(git ls-tree -r origin/gh-pages:pr-preview --name-only 2>/dev/null | \ | ||
| grep -v '/\.' | \ | ||
| cut -d/ -f1 | \ | ||
| sort -u || true) | ||
|
|
||
| all_dirs=$(git ls-tree -d origin/gh-pages:pr-preview --name-only 2>/dev/null || true) | ||
|
|
||
| if [ -z "$all_dirs" ]; then | ||
| echo "No directories found in pr-preview or pr-preview does not exist" | ||
| rm "$REMOVE_PATHS_FILE" | ||
| exit 0 | ||
| fi | ||
|
|
||
| while IFS= read -r dir; do | ||
| if [ -n "$dir" ]; then | ||
| if ! echo "$dirs_with_visible_files" | grep -q "^${dir}$"; then | ||
| dir_path="pr-preview/$dir" | ||
| echo "Found directory to remove: $dir_path" | ||
| echo "$dir_path" >> "$REMOVE_PATHS_FILE" | ||
| fi | ||
| fi | ||
| done <<< "$all_dirs" | ||
|
|
||
| if [ ! -s "$REMOVE_PATHS_FILE" ]; then | ||
| echo "No empty or hidden-file-only directories found. Nothing to clean up." | ||
| rm "$REMOVE_PATHS_FILE" | ||
| exit 0 | ||
| fi | ||
|
|
||
| uvx git-filter-repo@2.47.0 --paths-from-file "$REMOVE_PATHS_FILE" --invert-paths --refs origin/gh-pages | ||
| CALLBACK=" | ||
| root, *rest = filename.split(b'/') | ||
| keep = b'''$dirs_with_visible_files'''.splitlines() | ||
| if root != b'pr-preview': | ||
| # keep anything outside of pr-preview | ||
| return filename | ||
| elif rest and rest[0] not in keep: | ||
| return None | ||
| else: | ||
| return filename | ||
| " | ||
|
Comment on lines
+21
to
+31
|
||
|
|
||
| uvx git-filter-repo@2.47.0 --filename-callback "$CALLBACK" --refs origin/gh-pages | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
all_dirsis used in the while loop but is never defined. The line that previously defined it (all_dirs=$(git ls-tree -d origin/gh-pages:pr-preview --name-only 2>/dev/null || true)) was removed in this change. This will cause the while loop to process an empty string, making lines 13-20 effectively dead code that never executes.