Skip to content
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

Add script to list LFS file by size #11

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install deps
run: apt update && apt install -y sudo wget curl openjdk-17-jdk
- name: Install Gradle
run: sudo bash ./.tools/installGradle-8.11.sh
run: sudo bash ./.tools/installGradle-8.11.1.sh
- name: Check Gradle
run: gradle --version
install-gradle-windows-test:
Expand All @@ -42,7 +42,7 @@ jobs:
}
- name: Install Gradle
shell: pwsh
run: .tools/installGradle-8.11.ps1
run: .tools/installGradle-8.11.1.ps1
- name: Refresh environment
shell: pwsh
run: |
Expand Down
29 changes: 29 additions & 0 deletions .tools/list_lfs_by_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Function to convert human-readable sizes to bytes
size_to_bytes() {
local size=$(echo $1 | cut -d' ' -f1)
local unit=$(echo $1 | cut -d' ' -f2)
size=${size%.*} # Remove decimal part
case $unit in
KB) echo $((size * 1024)) ;;
MB) echo $((size * 1024 * 1024)) ;;
GB) echo $((size * 1024 * 1024 * 1024)) ;;
*) echo $size ;;
esac
}

# Get LFS files, convert sizes to bytes, sort, and print
git lfs ls-files -s |
while IFS= read -r line; do
if [[ $line =~ (.*)\((.*)\)$ ]]; then
file_path="${BASH_REMATCH[1]}"
size_str="${BASH_REMATCH[2]}"
size_bytes=$(size_to_bytes "$size_str")
printf "%020d|%s|%s\n" "$size_bytes" "$file_path" "$size_str"
fi
done |
sort -r |
while IFS='|' read -r size_bytes file_path size_str; do
echo "${file_path}(${size_str})"
done